Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2b7cb619e42bf318d230d749a41cf02e12bdab50 (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
/*******************************************************************************
 * 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.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
import org.eclipse.equinox.bidi.custom.STextProcessor;
import org.eclipse.equinox.bidi.internal.STextDelimsEsc;

/**
 *  Processor 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$
	}

	/**
	 *  @return {@link STextEngine#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 STextEngine#DIR_LTR DIR_LTR}.
	 */
	public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
		String language = environment.getLanguage();
		if (!language.equals("ar")) //$NON-NLS-1$
			return STextEngine.DIR_LTR;
		int domainStart;
		domainStart = text.indexOf('@');
		if (domainStart < 0)
			domainStart = 0;
		for (int i = domainStart; i < text.length(); i++) {
			byte dirProp = STextProcessor.getDirProp(text, dirProps, i);
			if (dirProp == AL || dirProp == R)
				return STextEngine.DIR_RTL;
		}
		return STextEngine.DIR_LTR;
	}

	/**
	 *  @return 2 as number of special cases handled by this processor.
	 */
	public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
		return 2;
	}

	/**
	 *  @return parentheses and quotation marks as delimiters.
	 */
	protected String getDelimiters() {
		return "()\"\""; //$NON-NLS-1$
	}

}

Back to the top