blob: 3f4796581cc4a139670e92f80bc6b73ad653e8af (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*******************************************************************************
* Copyright (c) 2010, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextDirection;
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.custom.STextCharTypes;
import org.eclipse.equinox.bidi.internal.STextDelimsEsc;
/**
* Handler adapted to processing e-mail addresses.
*/
public class STextEmail extends STextDelimsEsc {
static final byte L = Character.DIRECTIONALITY_LEFT_TO_RIGHT;
static final byte R = Character.DIRECTIONALITY_RIGHT_TO_LEFT;
static final byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
public STextEmail() {
super("<>.:,;@"); //$NON-NLS-1$
}
public int getDirection(ISTextExpert expert, String text) {
return getDirection(expert, text, new STextCharTypes(expert, text));
}
/**
* @return {@link STextDirection#DIR_RTL DIR_RTL} if the following
* conditions are satisfied:
* <ul>
* <li>The current locale (as expressed by the environment
* language) is Arabic.</li>
* <li>The domain part of the email address contains
* at least one RTL character.</li>
* </ul>
* Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
*/
public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
String language = expert.getEnvironment().getLanguage();
if (!language.equals("ar")) //$NON-NLS-1$
return STextDirection.DIR_LTR;
int domainStart;
domainStart = text.indexOf('@');
if (domainStart < 0)
domainStart = 0;
for (int i = domainStart; i < text.length(); i++) {
byte charType = charTypes.getBidiTypeAt(i);
if (charType == AL || charType == R)
return STextDirection.DIR_RTL;
}
return STextDirection.DIR_LTR;
}
/**
* @return 2 as number of special cases handled by this handler.
*/
public int getSpecialsCount(ISTextExpert expert) {
return 2;
}
/**
* @return parentheses and quotation marks as delimiters.
*/
protected String getDelimiters() {
return "()\"\""; //$NON-NLS-1$
}
}
|