View | Details | Raw Unified | Return to bug 183164 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/bidi/STextProcessor.java (-6 / +7 lines)
Lines 91-101 Link Here
91
			curMark = LRM;
91
			curMark = LRM;
92
			curPrefix = "\u202a\u200e"; /* LRE+LRM *///$NON-NLS-1$
92
			curPrefix = "\u202a\u200e"; /* LRE+LRM *///$NON-NLS-1$
93
			curSuffix = "\u200e\u202c"; /* LRM+PDF *///$NON-NLS-1$
93
			curSuffix = "\u200e\u202c"; /* LRM+PDF *///$NON-NLS-1$
94
		} else {
94
		} else if (direction == STextDirection.DIR_RTL) {
95
			curMark = RLM;
95
			curMark = RLM;
96
			curPrefix = "\u202b\u200f"; /* RLE+RLM *///$NON-NLS-1$
96
			curPrefix = "\u202b\u200f"; /* RLE+RLM *///$NON-NLS-1$
97
			curSuffix = "\u200f\u202c"; /* RLM+PDF *///$NON-NLS-1$
97
			curSuffix = "\u200f\u202c"; /* RLM+PDF *///$NON-NLS-1$
98
		}
98
		} else
99
			throw new IllegalArgumentException();
99
		// add marks at offsets
100
		// add marks at offsets
100
		if ((offsets != null) && (offsets.length > 0)) {
101
		if ((offsets != null) && (offsets.length > 0)) {
101
			int offLen = offsets.length;
102
			int offLen = offsets.length;
Lines 201-207 Link Here
201
	 * @param  handler a handler instance appropriate for the type of the structured text
202
	 * @param  handler a handler instance appropriate for the type of the structured text
202
	 * @return the processed string
203
	 * @return the processed string
203
	 */
204
	 */
204
	public static String process(String str, STextTypeHandler handler) {
205
	public static String processTyped(String str, String textType) {
205
		if ((str == null) || (str.length() <= 1))
206
		if ((str == null) || (str.length() <= 1))
206
			return str;
207
			return str;
207
208
Lines 214-220 Link Here
214
		STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN);
215
		STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN);
215
		if (!env.isProcessingNeeded())
216
		if (!env.isProcessingNeeded())
216
			return str;
217
			return str;
217
		ISTextExpert expert = STextExpertFactory.getExpert(handler, env);
218
		ISTextExpert expert = STextExpertFactory.getExpert(textType, env);
218
		return expert.leanToFullText(str);
219
		return expert.leanToFullText(str);
219
	}
220
	}
220
221
Lines 254-260 Link Here
254
	 * @param  handler appropriate for the structured text
255
	 * @param  handler appropriate for the structured text
255
	 * @return string without directional formatting characters
256
	 * @return string without directional formatting characters
256
	 */
257
	 */
257
	public static String deprocess(String str, STextTypeHandler handler) {
258
	public static String deprocessTyped(String str, String textType) {
258
		if ((str == null) || (str.length() <= 1))
259
		if ((str == null) || (str.length() <= 1))
259
			return str;
260
			return str;
260
261
Lines 262-268 Link Here
262
		STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN);
263
		STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN);
263
		if (!env.isProcessingNeeded())
264
		if (!env.isProcessingNeeded())
264
			return str;
265
			return str;
265
		ISTextExpert expert = STextExpertFactory.getExpert(handler, env);
266
		ISTextExpert expert = STextExpertFactory.getExpert(textType, env);
266
		return expert.fullToLeanText(str);
267
		return expert.fullToLeanText(str);
267
	}
268
	}
268
269
(-)src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java (-2 / +8 lines)
Lines 10-15 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.equinox.bidi.advanced;
11
package org.eclipse.equinox.bidi.advanced;
12
12
13
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
14
13
/**
15
/**
14
 * For a general introduction to structured text, see
16
 * For a general introduction to structured text, see
15
 * {@link <a href="package-summary.html"> the package documentation</a>}.
17
 * {@link <a href="package-summary.html"> the package documentation</a>}.
Lines 94-99 Link Here
94
	 *  {@link #getCurDirection getCurDirection} method.
96
	 *  {@link #getCurDirection getCurDirection} method.
95
	 */
97
	 */
96
	public static final int DIR_RTL = 1;
98
	public static final int DIR_RTL = 1;
99
100
	public STextTypeHandler getTypeHandler();
101
102
	public STextEnvironment getEnvironment();
97
103
98
	/** 
104
	/** 
99
	 * Add directional formatting characters to a structured text
105
	 * Add directional formatting characters to a structured text
Lines 256-262 Link Here
256
	 *
262
	 *
257
	 * @return the base direction of the structured text, {@link #DIR_LTR} or {@link #DIR_RTL}
263
	 * @return the base direction of the structured text, {@link #DIR_LTR} or {@link #DIR_RTL}
258
	 */
264
	 */
259
	public int getCurDirection(String text);
265
	public int getTextDirection(String text);
260
266
261
	///////////////////////////////////////////////////////////////////////////////////////////////
267
	///////////////////////////////////////////////////////////////////////////////////////////////
262
	// Expert's state handling - can be used only for non-shared experts
268
	// Expert's state handling - can be used only for non-shared experts
Lines 271-275 Link Here
271
	/**
277
	/**
272
	 * Resets state to initial.
278
	 * Resets state to initial.
273
	 */
279
	 */
274
	public void resetState();
280
	public void clearState();
275
}
281
}
(-)src/org/eclipse/equinox/bidi/advanced/STextEnvironment.java (-5 / +11 lines)
Lines 36-61 Link Here
36
36
37
	/**
37
	/**
38
	 * Specifies that a GUI component should display text depending on the context
38
	 * Specifies that a GUI component should display text depending on the context
39
	 * (value is 2).
40
	 */
41
	public static final int ORIENT_CONTEXTUAL = 1 << 1;
42
43
	/**
44
	 * Specifies that a GUI component should display text depending on the context
39
	 * with default orientation being Left-To-Right (value is 2).
45
	 * with default orientation being Left-To-Right (value is 2).
40
	 */
46
	 */
41
	public static final int ORIENT_CONTEXTUAL_LTR = 2;
47
	public static final int ORIENT_CONTEXTUAL_LTR = ORIENT_CONTEXTUAL | ORIENT_LTR;
42
48
43
	/**
49
	/**
44
	 * Specifies that a GUI component should display text depending on the context
50
	 * Specifies that a GUI component should display text depending on the context
45
	 * with default orientation being Right-To-Left (value is 3).
51
	 * with default orientation being Right-To-Left (value is 3).
46
	 */
52
	 */
47
	public static final int ORIENT_CONTEXTUAL_RTL = 3;
53
	public static final int ORIENT_CONTEXTUAL_RTL = ORIENT_CONTEXTUAL | ORIENT_RTL;
48
54
49
	/**
55
	/**
50
	 * Used when the orientation of a GUI component is not known (value is 4). 
56
	 * Used when the orientation of a GUI component is not known (value is 4). 
51
	 */
57
	 */
52
	public static final int ORIENT_UNKNOWN = 4;
58
	public static final int ORIENT_UNKNOWN = 1 << 2;
53
59
54
	/**
60
	/**
55
	 * Used to specify that no directional formatting characters 
61
	 * Used to specify that no directional formatting characters 
56
	 * should be added as prefix or suffix (value is 5).
62
	 * should be added as prefix or suffix (value is 8).
57
	 */
63
	 */
58
	public static final int ORIENT_IGNORE = 5;
64
	public static final int ORIENT_IGNORE = 1 << 3;
59
65
60
	/**
66
	/**
61
	 * Pre-defined <code>STextEnvironment</code> instance which uses default locale,
67
	 * Pre-defined <code>STextEnvironment</code> instance which uses default locale,
(-)src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java (+6 lines)
Lines 58-63 Link Here
58
58
59
	static public ISTextExpert getExpert(String type, STextEnvironment environment) {
59
	static public ISTextExpert getExpert(String type, STextEnvironment environment) {
60
		ISTextExpert expert;
60
		ISTextExpert expert;
61
		if (environment == null)
62
			environment = STextEnvironment.DEFAULT;
61
		synchronized (sharedExperts) {
63
		synchronized (sharedExperts) {
62
			Map experts = (Map) sharedExperts.get(type);
64
			Map experts = (Map) sharedExperts.get(type);
63
			if (experts == null) {
65
			if (experts == null) {
Lines 77-82 Link Here
77
	}
79
	}
78
80
79
	static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) {
81
	static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) {
82
		if (environment == null)
83
			environment = STextEnvironment.DEFAULT;
80
		return new STextImpl(handler, environment, true);
84
		return new STextImpl(handler, environment, true);
81
	}
85
	}
82
86
Lines 88-93 Link Here
88
		STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
92
		STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
89
		if (handler == null)
93
		if (handler == null)
90
			return null;
94
			return null;
95
		if (environment == null)
96
			environment = STextEnvironment.DEFAULT;
91
		return new STextImpl(handler, environment, true);
97
		return new STextImpl(handler, environment, true);
92
	}
98
	}
93
99
(-)src/org/eclipse/equinox/bidi/custom/STextCharTypes.java (-7 / +10 lines)
Lines 10-15 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.equinox.bidi.custom;
11
package org.eclipse.equinox.bidi.custom;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
14
15
15
/**
16
/**
Lines 35-40 Link Here
35
36
36
	private static final int CHARTYPES_ADD = 2;
37
	private static final int CHARTYPES_ADD = 2;
37
38
39
	final protected ISTextExpert expert;
38
	final protected STextTypeHandler handler;
40
	final protected STextTypeHandler handler;
39
	final protected STextEnvironment environment;
41
	final protected STextEnvironment environment;
40
	final protected String text;
42
	final protected String text;
Lines 59-74 Link Here
59
	 *  
61
	 *  
60
	 *  @param text is the text whose characters are analyzed.
62
	 *  @param text is the text whose characters are analyzed.
61
	 */
63
	 */
62
	public STextCharTypes(STextTypeHandler handler, STextEnvironment environment, String text) {
64
	public STextCharTypes(ISTextExpert expert, String text) {
63
		this.handler = handler;
65
		this.expert = expert;
64
		this.environment = environment;
66
		this.handler = expert.getTypeHandler();
67
		this.environment = expert.getEnvironment();
65
		this.text = text;
68
		this.text = text;
66
		types = new byte[text.length()];
69
		types = new byte[text.length()];
67
	}
70
	}
68
71
69
	public int getDirection() {
72
	public int getDirection() {
70
		if (direction < 0)
73
		if (direction < 0)
71
			direction = handler.getDirection(environment, text, this);
74
			direction = handler.getDirection(expert, text, this);
72
		return direction;
75
		return direction;
73
	}
76
	}
74
77
Lines 99-105 Link Here
99
				if (direction < -1) // called by handler.getDirection
102
				if (direction < -1) // called by handler.getDirection
100
					return charType; // avoid infinite recursion
103
					return charType; // avoid infinite recursion
101
				direction = -2; // signal we go within handler.getDirection
104
				direction = -2; // signal we go within handler.getDirection
102
				direction = handler.getDirection(environment, text, this);
105
				direction = handler.getDirection(expert, text, this);
103
			}
106
			}
104
			charType = (direction == STextEnvironment.ORIENT_RTL) ? R : L;
107
			charType = (direction == STextEnvironment.ORIENT_RTL) ? R : L;
105
		}
108
		}
Lines 136-146 Link Here
136
	 */
139
	 */
137
	public int resolveOrientation(STextEnvironment envir) {
140
	public int resolveOrientation(STextEnvironment envir) {
138
		int orient = envir.getOrientation();
141
		int orient = envir.getOrientation();
139
		if ((orient & STextEnvironment.ORIENT_CONTEXTUAL_LTR) == 0) { // absolute orientation
142
		if ((orient & STextEnvironment.ORIENT_CONTEXTUAL) == 0) { // absolute orientation
140
			return orient;
143
			return orient;
141
		}
144
		}
142
		// contextual orientation:
145
		// contextual orientation:
143
		orient &= 1; // initiate to the default orientation minus contextual bit
146
		orient &= ~STextEnvironment.ORIENT_CONTEXTUAL; // initiate to the default orientation minus contextual bit
144
		int len = text.length();
147
		int len = text.length();
145
		byte charType;
148
		byte charType;
146
		for (int i = 0; i < len; i++) {
149
		for (int i = 0; i < len; i++) {
(-)src/org/eclipse/equinox/bidi/custom/STextOffsets.java (-14 / +7 lines)
Lines 51-57 Link Here
51
	/**
51
	/**
52
	 * Mark that all entries in the offsets array are unused.
52
	 * Mark that all entries in the offsets array are unused.
53
	 */
53
	 */
54
	public void resetCount() {
54
	public void clear() {
55
		count = 0;
55
		count = 0;
56
	}
56
	}
57
57
Lines 71-76 Link Here
71
	 * @param  offset is the value to insert.
71
	 * @param  offset is the value to insert.
72
	 */
72
	 */
73
	public void insertOffset(STextCharTypes charTypes, int offset) {
73
	public void insertOffset(STextCharTypes charTypes, int offset) {
74
		if (count >= offsets.length) {
75
			int[] newOffsets = new int[offsets.length * 2];
76
			System.arraycopy(offsets, 0, newOffsets, 0, count);
77
			offsets = newOffsets;
78
		}
74
		int index = count - 1; // index of greatest member <= offset
79
		int index = count - 1; // index of greatest member <= offset
75
		// look up after which member the new offset should be inserted
80
		// look up after which member the new offset should be inserted
76
		while (index >= 0) {
81
		while (index >= 0) {
Lines 106-130 Link Here
106
			direction = charTypes.getDirection();
111
			direction = charTypes.getDirection();
107
		charTypes.setBidiTypeAt(index, STRONGS[direction]);
112
		charTypes.setBidiTypeAt(index, STRONGS[direction]);
108
		return;
113
		return;
109
	}
110
111
	/**
112
	 * Make sure that there is at least 3 free entries in the offsets array.
113
	 */
114
	public void ensureRoom() {
115
		// make sure there are at least 3 empty slots in offsets
116
		if ((offsets.length - count) < 3) {
117
			int[] newOffsets = new int[offsets.length * 2];
118
			System.arraycopy(offsets, 0, newOffsets, 0, count);
119
			offsets = newOffsets;
120
		}
121
	}
114
	}
122
115
123
	/**
116
	/**
124
	 * Get all and only the used offset entries.
117
	 * Get all and only the used offset entries.
125
	 * @return the current used entries of the offsets array.
118
	 * @return the current used entries of the offsets array.
126
	 */
119
	 */
127
	public int[] getArray() {
120
	public int[] getOffsets() {
128
		if (count == offsets.length)
121
		if (count == offsets.length)
129
			return offsets;
122
			return offsets;
130
		int[] array = new int[count];
123
		int[] array = new int[count];
(-)src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java (-10 / +10 lines)
Lines 36-42 Link Here
36
 *              See {@link #getSpecialsCount getSpecialsCount}.</li>
36
 *              See {@link #getSpecialsCount getSpecialsCount}.</li>
37
 *        </ul></li>
37
 *        </ul></li>
38
 *    <li>Before starting deeper analysis of the submitted text, the common
38
 *    <li>Before starting deeper analysis of the submitted text, the common
39
 *        logic gives to the handler a chance to shorten the processus by
39
 *        logic gives to the handler a chance to shorten the process by
40
 *        invoking its {@link #skipProcessing skipProcessing} method.</li>
40
 *        invoking its {@link #skipProcessing skipProcessing} method.</li>
41
 *    <li>The common logic then analyzes the text to segment it into tokens
41
 *    <li>The common logic then analyzes the text to segment it into tokens
42
 *        according to the appearance of separators (as retrieved using
42
 *        according to the appearance of separators (as retrieved using
Lines 46-56 Link Here
46
 *        method, the common logic will repeatedly invoke the handler's
46
 *        method, the common logic will repeatedly invoke the handler's
47
 *        {@link #indexOfSpecial indexOfSpecial} method to let it signal the
47
 *        {@link #indexOfSpecial indexOfSpecial} method to let it signal the
48
 *        presence of special strings which may further delimit the source text.</li>
48
 *        presence of special strings which may further delimit the source text.</li>
49
 *    <li>When such a special case is signalled by the handler, the common
49
 *    <li>When such a special case is signaled by the handler, the common
50
 *        logic will call the handler's {@link #processSpecial processSpecial}
50
 *        logic will call the handler's {@link #processSpecial processSpecial}
51
 *        method to give it the opportunity to handle it as needed. Typical
51
 *        method to give it the opportunity to handle it as needed. Typical
52
 *        actions that the handler may perform are to add directional marks
52
 *        actions that the handler may perform are to add directional marks
53
 *        inconditionally (by calling {@link #insertMark insertMark} or
53
 *        unconditionally (by calling {@link #insertMark insertMark} or
54
 *        conditionally (by calling {@link #processSeparator processSeparator}).</li>
54
 *        conditionally (by calling {@link #processSeparator processSeparator}).</li>
55
 *  </ul>
55
 *  </ul>
56
 *
56
 *
Lines 127-133 Link Here
127
	 * number of special cases is zero, which means that
127
	 * number of special cases is zero, which means that
128
	 * <code>indexOfSpecial</code> should never be called for them.
128
	 * <code>indexOfSpecial</code> should never be called for them.
129
	 */
129
	 */
130
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
130
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
131
		// This method must be overridden by all subclasses with special cases.
131
		// This method must be overridden by all subclasses with special cases.
132
		throw new IllegalStateException("A handler with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$
132
		throw new IllegalStateException("A handler with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$
133
	}
133
	}
Lines 210-216 Link Here
210
	 * number of special cases is zero, which means that
210
	 * number of special cases is zero, which means that
211
	 * <code>processSpecial</code> should never be called for them.
211
	 * <code>processSpecial</code> should never be called for them.
212
	 */
212
	 */
213
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
213
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
214
		// This method must be overridden by all subclasses with any special case.
214
		// This method must be overridden by all subclasses with any special case.
215
		throw new IllegalStateException("A handler with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$
215
		throw new IllegalStateException("A handler with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$
216
	}
216
	}
Lines 300-306 Link Here
300
	 * @return a string grouping one-character separators which separate
300
	 * @return a string grouping one-character separators which separate
301
	 *         the structured text into tokens.
301
	 *         the structured text into tokens.
302
	 */
302
	 */
303
	public String getSeparators(STextEnvironment environment) {
303
	public String getSeparators(ISTextExpert expert) {
304
		return separators;
304
		return separators;
305
	}
305
	}
306
306
Lines 325-331 Link Here
325
	 *         The value returned is either
325
	 *         The value returned is either
326
	 *         {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
326
	 *         {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
327
	 */
327
	 */
328
	public int getDirection(STextEnvironment environment, String text) {
328
	public int getDirection(ISTextExpert expert, String text) {
329
		return STextDirection.DIR_LTR;
329
		return STextDirection.DIR_LTR;
330
	}
330
	}
331
331
Lines 354-360 Link Here
354
	 *         The value returned is either
354
	 *         The value returned is either
355
	 *         {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
355
	 *         {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
356
	 */
356
	 */
357
	public int getDirection(STextEnvironment environment, String text, STextCharTypes charTypes) {
357
	public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
358
		return STextDirection.DIR_LTR;
358
		return STextDirection.DIR_LTR;
359
	}
359
	}
360
360
Lines 380-386 Link Here
380
	 *         anything which is not identified by a one-character separator.
380
	 *         anything which is not identified by a one-character separator.
381
	 *
381
	 *
382
	 */
382
	 */
383
	public int getSpecialsCount(STextEnvironment environment) {
383
	public int getSpecialsCount(ISTextExpert expert) {
384
		return 0;
384
		return 0;
385
	}
385
	}
386
386
Lines 409-415 Link Here
409
	 *         text to add directional formatting characters.
409
	 *         text to add directional formatting characters.
410
	 *
410
	 *
411
	 */
411
	 */
412
	public boolean skipProcessing(STextEnvironment environment, String text, STextCharTypes charTypes) {
412
	public boolean skipProcessing(ISTextExpert expert, String text, STextCharTypes charTypes) {
413
		return false;
413
		return false;
414
	}
414
	}
415
415
(-)src/org/eclipse/equinox/bidi/internal/STextDelims.java (-3 / +2 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal;
11
package org.eclipse.equinox.bidi.internal;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
15
import org.eclipse.equinox.bidi.custom.*;
14
import org.eclipse.equinox.bidi.custom.*;
16
15
17
/**
16
/**
Lines 44-50 Link Here
44
	 *
43
	 *
45
	 *  @see #getDelimiters
44
	 *  @see #getDelimiters
46
	 */
45
	 */
47
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
46
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
48
		char delim = getDelimiters().charAt((caseNumber - 1) * 2);
47
		char delim = getDelimiters().charAt((caseNumber - 1) * 2);
49
		return text.indexOf(delim, fromIndex);
48
		return text.indexOf(delim, fromIndex);
50
	}
49
	}
Lines 59-65 Link Here
59
	 *  @return the position after the matching end delimiter, or the length
58
	 *  @return the position after the matching end delimiter, or the length
60
	 *          of <code>text</code> if no end delimiter is found.
59
	 *          of <code>text</code> if no end delimiter is found.
61
	 */
60
	 */
62
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
61
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
63
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
62
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
64
		int loc = separLocation + 1;
63
		int loc = separLocation + 1;
65
		char delim = getDelimiters().charAt((caseNumber * 2) - 1);
64
		char delim = getDelimiters().charAt((caseNumber * 2) - 1);
(-)src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java (-2 / +1 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal;
11
package org.eclipse.equinox.bidi.internal;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
15
import org.eclipse.equinox.bidi.custom.*;
14
import org.eclipse.equinox.bidi.custom.*;
16
15
17
/**
16
/**
Lines 50-56 Link Here
50
	 *  and skips until after the matching end delimiter,
49
	 *  and skips until after the matching end delimiter,
51
	 *  ignoring possibly escaped end delimiters.
50
	 *  ignoring possibly escaped end delimiters.
52
	 */
51
	 */
53
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
52
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
54
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
53
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
55
		int location = separLocation + 1;
54
		int location = separLocation + 1;
56
		char delim = getDelimiters().charAt((caseNumber * 2) - 1);
55
		char delim = getDelimiters().charAt((caseNumber * 2) - 1);
(-)src/org/eclipse/equinox/bidi/internal/STextImpl.java (-113 / +101 lines)
Lines 46-95 Link Here
46
	static final int SUFFIX_LENGTH = 2;
46
	static final int SUFFIX_LENGTH = 2;
47
	static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH;
47
	static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH;
48
	static final int[] EMPTY_INT_ARRAY = new int[0];
48
	static final int[] EMPTY_INT_ARRAY = new int[0];
49
	static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE);
50
49
51
	protected STextTypeHandler structuredTextHandler;
50
	protected final STextTypeHandler handler;
52
	protected STextEnvironment environment;
51
	protected final STextEnvironment environment;
53
52
	protected final boolean sharedExpert;
54
	protected Object state;
53
	protected Object state;
55
54
56
	protected boolean sharedExpert;
57
58
	public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, boolean shared) {
55
	public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, boolean shared) {
59
		this.structuredTextHandler = structuredTextHandler;
56
		this.handler = structuredTextHandler;
60
		this.environment = environment;
57
		this.environment = environment;
61
		sharedExpert = shared;
58
		sharedExpert = shared;
62
	}
59
	}
63
60
64
	public String leanToFullText(String text) {
61
	public STextTypeHandler getTypeHandler() {
65
		return leanToFullText(structuredTextHandler, environment, text, state);
62
		return handler;
66
	}
63
	}
67
64
68
	public int[] leanToFullMap(String text) {
65
	public STextEnvironment getEnvironment() {
69
		return leanToFullMap(structuredTextHandler, environment, text, state);
66
		return environment;
70
	}
67
	}
71
68
72
	public int[] leanBidiCharOffsets(String text) {
69
	public int getTextDirection(String text) {
73
		return leanBidiCharOffsets(structuredTextHandler, environment, text, state);
70
		return handler.getDirection(this, text);
74
	}
71
	}
75
72
76
	public String fullToLeanText(String text) {
73
	public void clearState() {
77
		return fullToLeanText(structuredTextHandler, environment, text, state);
78
	}
79
80
	public int[] fullToLeanMap(String text) {
81
		return fullToLeanMap(structuredTextHandler, environment, text, state);
82
	}
83
84
	public int[] fullBidiCharOffsets(String text) {
85
		return fullBidiCharOffsets(structuredTextHandler, environment, text, state);
86
	}
87
88
	public int getCurDirection(String text) {
89
		return structuredTextHandler.getDirection(environment, text);
90
	}
91
92
	public void resetState() {
93
		if (sharedExpert)
74
		if (sharedExpert)
94
			state = null;
75
			state = null;
95
	}
76
	}
Lines 103-112 Link Here
103
		return state;
84
		return state;
104
	}
85
	}
105
86
106
	long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) {
87
	long computeNextLocation(String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) {
107
		String separators = handler.getSeparators(environment);
88
		String separators = handler.getSeparators(this);
108
		int separCount = separators.length();
89
		int separCount = separators.length();
109
		int specialsCount = handler.getSpecialsCount(environment);
90
		int specialsCount = handler.getSpecialsCount(this);
110
		int len = text.length();
91
		int len = text.length();
111
		int nextLocation = len;
92
		int nextLocation = len;
112
		int idxLocation = 0;
93
		int idxLocation = 0;
Lines 115-122 Link Here
115
		for (int i = 0; i < specialsCount; i++) {
96
		for (int i = 0; i < specialsCount; i++) {
116
			int location = locations[separCount + i];
97
			int location = locations[separCount + i];
117
			if (location < curPos) {
98
			if (location < curPos) {
118
				offsets.ensureRoom();
99
				location = handler.indexOfSpecial(this, text, charTypes, offsets, i + 1, curPos);
119
				location = handler.indexOfSpecial(environment, text, charTypes, offsets, i + 1, curPos);
120
				if (location < 0)
100
				if (location < 0)
121
					location = len;
101
					location = len;
122
				locations[separCount + i] = location;
102
				locations[separCount + i] = location;
Lines 243-254 Link Here
243
	 *  <p>
223
	 *  <p>
244
	 *  @see ISTextExpert#leanToFullText STextEngine.leanToFullText
224
	 *  @see ISTextExpert#leanToFullText STextEngine.leanToFullText
245
	 */
225
	 */
246
	public String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) {
226
	public String leanToFullText(String text) {
247
		int len = text.length();
227
		int len = text.length();
248
		if (len == 0)
228
		if (len == 0)
249
			return text;
229
			return text;
250
		STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
230
		STextCharTypes charTypes = new STextCharTypes(this, text);
251
		STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
231
		STextOffsets offsets = leanToFullCommon(text, charTypes);
252
		int prefixLength = offsets.getPrefixLength();
232
		int prefixLength = offsets.getPrefixLength();
253
		int count = offsets.getCount();
233
		int count = offsets.getCount();
254
		if (count == 0 && prefixLength == 0)
234
		if (count == 0 && prefixLength == 0)
Lines 290-301 Link Here
290
		return new String(fullChars);
270
		return new String(fullChars);
291
	}
271
	}
292
272
293
	public int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, Object state) {
273
	public int[] leanToFullMap(String text) {
294
		int len = text.length();
274
		int len = text.length();
295
		if (len == 0)
275
		if (len == 0)
296
			return EMPTY_INT_ARRAY;
276
			return EMPTY_INT_ARRAY;
297
		STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
277
		STextCharTypes charTypes = new STextCharTypes(this, text);
298
		STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
278
		STextOffsets offsets = leanToFullCommon(text, charTypes);
299
		int prefixLength = offsets.getPrefixLength();
279
		int prefixLength = offsets.getPrefixLength();
300
		int[] map = new int[len];
280
		int[] map = new int[len];
301
		int count = offsets.getCount(); // number of used entries
281
		int count = offsets.getCount(); // number of used entries
Lines 310-360 Link Here
310
		return map;
290
		return map;
311
	}
291
	}
312
292
313
	public int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, Object state) {
293
	public int[] leanBidiCharOffsets(String text) {
314
		int len = text.length();
294
		int len = text.length();
315
		if (len == 0)
295
		if (len == 0)
316
			return EMPTY_INT_ARRAY;
296
			return EMPTY_INT_ARRAY;
317
		STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
297
		STextCharTypes charTypes = new STextCharTypes(this, text);
318
		STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
298
		STextOffsets offsets = leanToFullCommon(text, charTypes);
319
		return offsets.getArray();
299
		return offsets.getOffsets();
320
	}
300
	}
321
301
322
	public STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, Object state, STextCharTypes charTypes) {
302
	private STextOffsets leanToFullCommon(String text, STextCharTypes charTypes) {
323
		if (environment == null)
324
			environment = STextEnvironment.DEFAULT;
325
		int len = text.length();
303
		int len = text.length();
326
		int direction = handler.getDirection(environment, text, charTypes);
304
		int direction = handler.getDirection(this, text, charTypes);
327
		STextOffsets offsets = new STextOffsets();
305
		STextOffsets offsets = new STextOffsets();
328
		if (!handler.skipProcessing(environment, text, charTypes)) {
306
		if (!handler.skipProcessing(this, text, charTypes)) {
329
			// initialize locations
307
			// initialize locations
330
			int separCount = handler.getSeparators(environment).length();
308
			int separCount = handler.getSeparators(this).length();
331
			int[] locations = new int[separCount + handler.getSpecialsCount(environment)];
309
			int[] locations = new int[separCount + handler.getSpecialsCount(this)];
332
			for (int i = 0, k = locations.length; i < k; i++) {
310
			for (int i = 0, k = locations.length; i < k; i++) {
333
				locations[i] = -1;
311
				locations[i] = -1;
334
			}
312
			}
335
			// current position
313
			// current position
336
			int curPos = 0;
314
			int curPos = 0;
337
			if (state != null) {
315
			if (state != null) {
338
				offsets.ensureRoom();
316
				curPos = handler.processSpecial(this, text, charTypes, offsets, 0, -1);
339
				curPos = handler.processSpecial(this, environment, text, charTypes, offsets, 0, -1);
340
			}
317
			}
341
			while (true) {
318
			while (true) {
342
				// location of next token to handle
319
				// location of next token to handle
343
				int nextLocation;
320
				int nextLocation;
344
				// index of next token to handle (if < separCount, this is a separator; otherwise a special case
321
				// index of next token to handle (if < separCount, this is a separator; otherwise a special case
345
				int idxLocation;
322
				int idxLocation;
346
				long res = computeNextLocation(handler, environment, text, charTypes, offsets, locations, curPos);
323
				long res = computeNextLocation(text, charTypes, offsets, locations, curPos);
347
				nextLocation = (int) (res & 0x00000000FFFFFFFF); /* low word */
324
				nextLocation = (int) (res & 0x00000000FFFFFFFF); /* low word */
348
				if (nextLocation >= len)
325
				if (nextLocation >= len)
349
					break;
326
					break;
350
				offsets.ensureRoom();
351
				idxLocation = (int) (res >> 32); /* high word */
327
				idxLocation = (int) (res >> 32); /* high word */
352
				if (idxLocation < separCount) {
328
				if (idxLocation < separCount) {
353
					processSeparator(text, charTypes, offsets, nextLocation);
329
					processSeparator(text, charTypes, offsets, nextLocation);
354
					curPos = nextLocation + 1;
330
					curPos = nextLocation + 1;
355
				} else {
331
				} else {
356
					idxLocation -= (separCount - 1); // because caseNumber starts from 1
332
					idxLocation -= (separCount - 1); // because caseNumber starts from 1
357
					curPos = handler.processSpecial(this, environment, text, charTypes, offsets, idxLocation, nextLocation);
333
					curPos = handler.processSpecial(this, text, charTypes, offsets, idxLocation, nextLocation);
358
				}
334
				}
359
				if (curPos >= len)
335
				if (curPos >= len)
360
					break;
336
					break;
Lines 368-374 Link Here
368
			int resolvedOrientation = charTypes.resolveOrientation(environment);
344
			int resolvedOrientation = charTypes.resolveOrientation(environment);
369
			if (orientation != STextEnvironment.ORIENT_UNKNOWN && resolvedOrientation == direction)
345
			if (orientation != STextEnvironment.ORIENT_UNKNOWN && resolvedOrientation == direction)
370
				prefixLength = 0;
346
				prefixLength = 0;
371
			else if ((orientation & STextEnvironment.ORIENT_CONTEXTUAL_LTR) != 0)
347
			else if ((orientation & STextEnvironment.ORIENT_CONTEXTUAL) != 0)
372
				prefixLength = 1;
348
				prefixLength = 1;
373
			else
349
			else
374
				prefixLength = 2;
350
				prefixLength = 2;
Lines 377-477 Link Here
377
		return offsets;
353
		return offsets;
378
	}
354
	}
379
355
380
	public String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, Object state) {
356
	public String fullToLeanText(String full) {
381
		if (text.length() == 0)
357
		if (full.length() == 0)
382
			return text;
358
			return full;
383
		if (environment == null)
359
		int dir = handler.getDirection(this, full);
384
			environment = STextEnvironment.DEFAULT;
385
		int dir = handler.getDirection(environment, text);
386
		char curMark = MARKS[dir];
360
		char curMark = MARKS[dir];
387
		char curEmbed = EMBEDS[dir];
361
		char curEmbed = EMBEDS[dir];
388
		int i; // used as loop index
362
		int i; // used as loop index
389
		// remove any prefix and leading mark
363
		// remove any prefix and leading mark
390
		int lenText = text.length();
364
		int lenFull = full.length();
391
		for (i = 0; i < lenText; i++) {
365
		for (i = 0; i < lenFull; i++) {
392
			char c = text.charAt(i);
366
			char c = full.charAt(i);
393
			if (c != curEmbed && c != curMark)
367
			if (c != curEmbed && c != curMark)
394
				break;
368
				break;
395
		}
369
		}
396
		if (i > 0) { // found at least one prefix or leading mark
370
		if (i > 0) { // found at least one prefix or leading mark
397
			text = text.substring(i);
371
			full = full.substring(i);
398
			lenText = text.length();
372
			lenFull = full.length();
399
		}
373
		}
400
		// remove any suffix and trailing mark
374
		// remove any suffix and trailing mark
401
		for (i = lenText - 1; i >= 0; i--) {
375
		for (i = lenFull - 1; i >= 0; i--) {
402
			char c = text.charAt(i);
376
			char c = full.charAt(i);
403
			if (c != PDF && c != curMark)
377
			if (c != PDF && c != curMark)
404
				break;
378
				break;
405
		}
379
		}
406
		if (i < 0) // only suffix and trailing marks, no real data
380
		if (i < 0) // only suffix and trailing marks, no real data
407
			return EMPTY_STRING;
381
			return EMPTY_STRING;
408
		if (i < (lenText - 1)) { // found at least one suffix or trailing mark
382
		if (i < (lenFull - 1)) { // found at least one suffix or trailing mark
409
			text = text.substring(0, i + 1);
383
			full = full.substring(0, i + 1);
410
			lenText = text.length();
384
			lenFull = full.length();
411
		}
385
		}
412
		char[] chars = text.toCharArray();
386
		char[] chars = full.toCharArray();
413
		// remove marks from chars
387
		// remove marks from chars
414
		int cnt = 0;
388
		int cnt = 0;
415
		for (i = 0; i < lenText; i++) {
389
		for (i = 0; i < lenFull; i++) {
416
			char c = chars[i];
390
			char c = chars[i];
417
			if (c == curMark)
391
			if (c == curMark)
418
				cnt++;
392
				cnt++;
419
			else if (cnt > 0)
393
			else if (cnt > 0)
420
				chars[i - cnt] = c;
394
				chars[i - cnt] = c;
395
		}
396
		String lean = new String(chars, 0, lenFull - cnt);
397
		String full2 = leanToFullText(lean);
398
		// strip prefix and suffix
399
		int beginIndex = 0, endIndex = full2.length();
400
		if (full2.charAt(0) == curMark)
401
			beginIndex = 1;
402
		else {
403
			if (full2.charAt(0) == curEmbed) {
404
				beginIndex = 1;
405
				if (full2.charAt(0) == curMark)
406
					beginIndex = 2;
407
			}
408
			if (full2.charAt(endIndex - 1) == PDF) {
409
				endIndex--;
410
				if (full2.charAt(endIndex - 1) == curMark)
411
					endIndex--;
412
			}
421
		}
413
		}
422
		String lean = new String(chars, 0, lenText - cnt);
414
		if (beginIndex > 0 || endIndex < full2.length())
423
		String full = leanToFullText(handler, IGNORE_ENVIRONMENT, lean, state);
415
			full2 = full2.substring(beginIndex, endIndex);
424
		if (full.equals(text))
416
		if (full2.equals(full))
425
			return lean;
417
			return lean;
426
418
427
		// There are some marks in full which are not in text and/or vice versa.
419
		// There are some marks in full which are not in full2 and/or vice versa.
428
		// We need to add to lean any mark appearing in text and not in full.
420
		// We need to add to lean any mark appearing in full and not in full2.
429
		// The completed lean can never be longer than text itself.
421
		// The completed lean can never be longer than full itself.
430
		char[] newChars = new char[lenText];
422
		char[] newChars = new char[lenFull];
431
		char cFull, cText;
423
		char cFull, cFull2;
432
		int idxFull, idxText, idxLean, newCharsPos;
424
		int idxFull, idxFull2, idxLean, newCharsPos;
433
		int lenFull = full.length();
425
		int lenFull2 = full2.length();
434
		idxFull = idxText = idxLean = newCharsPos = 0;
426
		idxFull = idxFull2 = idxLean = newCharsPos = 0;
435
		while (idxText < lenText && idxFull < lenFull) {
427
		while (idxFull < lenFull && idxFull2 < lenFull2) {
428
			cFull2 = full2.charAt(idxFull2);
436
			cFull = full.charAt(idxFull);
429
			cFull = full.charAt(idxFull);
437
			cText = text.charAt(idxText);
430
			if (cFull2 == cFull) { /* chars are equal, proceed */
438
			if (cFull == cText) { /* chars are equal, proceed */
431
				if (cFull2 != curMark)
439
				if (cFull != curMark)
440
					newChars[newCharsPos++] = chars[idxLean++];
432
					newChars[newCharsPos++] = chars[idxLean++];
441
				idxText++;
442
				idxFull++;
433
				idxFull++;
434
				idxFull2++;
443
				continue;
435
				continue;
444
			}
436
			}
445
			if (cFull == curMark) { /* extra Mark in full text */
437
			if (cFull2 == curMark) { /* extra Mark in full2 text */
446
				idxFull++;
438
				idxFull2++;
447
				continue;
439
				continue;
448
			}
440
			}
449
			if (cText == curMark) { /* extra Mark in source full text */
441
			if (cFull == curMark) { /* extra Mark in source full text */
450
				idxText++;
442
				idxFull++;
451
				// idxText-2 always >= 0 since leading Marks were removed from text
443
				// idxFull-2 always >= 0 since leading Marks were removed from full
452
				if (text.charAt(idxText - 2) == curMark)
444
				if (full.charAt(idxFull - 2) == curMark)
453
					continue; // ignore successive Marks in text after the first one
445
					continue; // ignore successive Marks in full after the first one
454
				newChars[newCharsPos++] = curMark;
446
				newChars[newCharsPos++] = curMark;
455
				continue;
447
				continue;
456
			}
448
			}
457
			// we should never get here (extra char which is not a Mark)
449
			// we should never get here (extra char which is not a Mark)
458
			throw new IllegalStateException("Internal error: extra character not a Mark."); //$NON-NLS-1$
450
			throw new IllegalStateException("Internal error: extra character not a Mark."); //$NON-NLS-1$
459
		}
451
		}
460
		if (idxText < lenText) /* full ended before text - this should never happen since
452
		if (idxFull < lenFull) /* full2 ended before full - this should never happen since
461
								              we removed all marks and PDFs at the end of text */
453
								              we removed all marks and PDFs at the end of full */
462
			throw new IllegalStateException("Internal error: unexpected EOL."); //$NON-NLS-1$
454
			throw new IllegalStateException("Internal error: unexpected EOL."); //$NON-NLS-1$
463
455
464
		lean = new String(newChars, 0, newCharsPos);
456
		lean = new String(newChars, 0, newCharsPos);
465
		return lean;
457
		return lean;
466
	}
458
	}
467
459
468
	public int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, Object state) {
460
	public int[] fullToLeanMap(String full) {
469
		int lenFull = full.length();
461
		int lenFull = full.length();
470
		if (lenFull == 0)
462
		if (lenFull == 0)
471
			return EMPTY_INT_ARRAY;
463
			return EMPTY_INT_ARRAY;
472
		String lean = fullToLeanText(handler, environment, full, state);
464
		String lean = fullToLeanText(full);
473
		int lenLean = lean.length();
465
		int lenLean = lean.length();
474
		int dir = handler.getDirection(environment, lean);
466
		int dir = handler.getDirection(this, lean);
475
		char curMark = MARKS[dir];
467
		char curMark = MARKS[dir];
476
		char curEmbed = EMBEDS[dir];
468
		char curEmbed = EMBEDS[dir];
477
		int[] map = new int[lenFull];
469
		int[] map = new int[lenFull];
Lines 496-506 Link Here
496
		return map;
488
		return map;
497
	}
489
	}
498
490
499
	public int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, Object state) {
491
	public int[] fullBidiCharOffsets(String full) {
500
		int lenFull = full.length();
492
		int lenFull = full.length();
501
		if (lenFull == 0)
493
		if (lenFull == 0)
502
			return EMPTY_INT_ARRAY;
494
			return EMPTY_INT_ARRAY;
503
		String lean = fullToLeanText(handler, environment, full, state);
495
		String lean = fullToLeanText(full);
504
		STextOffsets offsets = new STextOffsets();
496
		STextOffsets offsets = new STextOffsets();
505
		int lenLean = lean.length();
497
		int lenLean = lean.length();
506
		int idxLean, idxFull;
498
		int idxLean, idxFull;
Lines 508-522 Link Here
508
		for (idxLean = idxFull = 0; idxLean < lenLean; idxFull++) {
500
		for (idxLean = idxFull = 0; idxLean < lenLean; idxFull++) {
509
			if (full.charAt(idxFull) == lean.charAt(idxLean))
501
			if (full.charAt(idxFull) == lean.charAt(idxLean))
510
				idxLean++;
502
				idxLean++;
511
			else {
503
			else
512
				offsets.ensureRoom();
513
				offsets.insertOffset(null, idxFull);
504
				offsets.insertOffset(null, idxFull);
514
			}
515
		}
505
		}
516
		for (; idxFull < lenFull; idxFull++) {
506
		for (; idxFull < lenFull; idxFull++)
517
			offsets.ensureRoom();
518
			offsets.insertOffset(null, idxFull);
507
			offsets.insertOffset(null, idxFull);
519
		}
508
		return offsets.getOffsets();
520
		return offsets.getArray();
521
	}
509
	}
522
}
510
}
(-)src/org/eclipse/equinox/bidi/internal/STextSingle.java (-5 / +4 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal;
11
package org.eclipse.equinox.bidi.internal;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
15
import org.eclipse.equinox.bidi.custom.*;
14
import org.eclipse.equinox.bidi.custom.*;
16
15
17
/**
16
/**
Lines 41-48 Link Here
41
	 *
40
	 *
42
	 *  @see #getSeparators getSeparators
41
	 *  @see #getSeparators getSeparators
43
	 */
42
	 */
44
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
43
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
45
		return text.indexOf(this.getSeparators(environment).charAt(0), fromIndex);
44
		return text.indexOf(this.getSeparators(expert).charAt(0), fromIndex);
46
	}
45
	}
47
46
48
	/**
47
	/**
Lines 51-57 Link Here
51
	 *
50
	 *
52
	 *  @return the length of <code>text</code>.
51
	 *  @return the length of <code>text</code>.
53
	 */
52
	 */
54
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
53
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
55
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
54
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
56
		return text.length();
55
		return text.length();
57
	}
56
	}
Lines 61-67 Link Here
61
	 *
60
	 *
62
	 *  @return 1.
61
	 *  @return 1.
63
	 */
62
	 */
64
	public int getSpecialsCount(STextEnvironment environment) {
63
	public int getSpecialsCount(ISTextExpert expert) {
65
		return 1;
64
		return 1;
66
	}
65
	}
67
66
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java (-6 / +6 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal.consumable;
11
package org.eclipse.equinox.bidi.internal.consumable;
12
12
13
import org.eclipse.equinox.bidi.STextDirection;
13
import org.eclipse.equinox.bidi.STextDirection;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
14
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
15
import org.eclipse.equinox.bidi.custom.STextCharTypes;
15
import org.eclipse.equinox.bidi.custom.STextCharTypes;
16
import org.eclipse.equinox.bidi.internal.STextDelimsEsc;
16
import org.eclipse.equinox.bidi.internal.STextDelimsEsc;
17
17
Lines 27-34 Link Here
27
		super("<>.:,;@"); //$NON-NLS-1$
27
		super("<>.:,;@"); //$NON-NLS-1$
28
	}
28
	}
29
29
30
	public int getDirection(STextEnvironment environment, String text) {
30
	public int getDirection(ISTextExpert expert, String text) {
31
		return getDirection(environment, text, new STextCharTypes(this, environment, text));
31
		return getDirection(expert, text, new STextCharTypes(expert, text));
32
	}
32
	}
33
33
34
	/**
34
	/**
Lines 42-49 Link Here
42
	 *          </ul>
42
	 *          </ul>
43
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
43
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
44
	 */
44
	 */
45
	public int getDirection(STextEnvironment environment, String text, STextCharTypes charTypes) {
45
	public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
46
		String language = environment.getLanguage();
46
		String language = expert.getEnvironment().getLanguage();
47
		if (!language.equals("ar")) //$NON-NLS-1$
47
		if (!language.equals("ar")) //$NON-NLS-1$
48
			return STextDirection.DIR_LTR;
48
			return STextDirection.DIR_LTR;
49
		int domainStart;
49
		int domainStart;
Lines 61-67 Link Here
61
	/**
61
	/**
62
	 *  @return 2 as number of special cases handled by this handler.
62
	 *  @return 2 as number of special cases handled by this handler.
63
	 */
63
	 */
64
	public int getSpecialsCount(STextEnvironment environment) {
64
	public int getSpecialsCount(ISTextExpert expert) {
65
		return 2;
65
		return 2;
66
	}
66
	}
67
67
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java (-5 / +4 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal.consumable;
11
package org.eclipse.equinox.bidi.internal.consumable;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
15
import org.eclipse.equinox.bidi.custom.*;
14
import org.eclipse.equinox.bidi.custom.*;
16
import org.eclipse.equinox.bidi.internal.STextActivator;
15
import org.eclipse.equinox.bidi.internal.STextActivator;
17
16
Lines 46-52 Link Here
46
	/**
45
	/**
47
	 *  @return 4 as the number of special cases handled by this handler.
46
	 *  @return 4 as the number of special cases handled by this handler.
48
	 */
47
	 */
49
	public int getSpecialsCount(STextEnvironment environment) {
48
	public int getSpecialsCount(ISTextExpert expert) {
50
		return 4;
49
		return 4;
51
	}
50
	}
52
51
Lines 59-65 Link Here
59
	     *    <li>comments starting with slash-slash</li>
58
	     *    <li>comments starting with slash-slash</li>
60
	     *  </ol>
59
	     *  </ol>
61
	     */
60
	     */
62
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
61
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
63
		switch (caseNumber) {
62
		switch (caseNumber) {
64
			case 1 : /* space */
63
			case 1 : /* space */
65
				return text.indexOf(' ', fromIndex);
64
				return text.indexOf(' ', fromIndex);
Lines 83-95 Link Here
83
	     *    <li>skip until after a line separator</li>
82
	     *    <li>skip until after a line separator</li>
84
	     *  </ol>
83
	     *  </ol>
85
	 */
84
	 */
86
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
85
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
87
		int location, counter, i;
86
		int location, counter, i;
88
87
89
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
88
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
90
		if (separLocation < 0) {
89
		if (separLocation < 0) {
91
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
90
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
92
			expert.resetState();
91
			expert.clearState();
93
		}
92
		}
94
		switch (caseNumber) {
93
		switch (caseNumber) {
95
			case 1 : /* space */
94
			case 1 : /* space */
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java (-5 / +5 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal.consumable;
11
package org.eclipse.equinox.bidi.internal.consumable;
12
12
13
import org.eclipse.equinox.bidi.STextDirection;
13
import org.eclipse.equinox.bidi.STextDirection;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
14
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
15
import org.eclipse.equinox.bidi.custom.STextCharTypes;
15
import org.eclipse.equinox.bidi.custom.STextCharTypes;
16
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
16
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
17
17
Lines 29-36 Link Here
29
		super("+-/*()="); //$NON-NLS-1$
29
		super("+-/*()="); //$NON-NLS-1$
30
	}
30
	}
31
31
32
	public int getDirection(STextEnvironment environment, String text) {
32
	public int getDirection(ISTextExpert expert, String text) {
33
		return getDirection(environment, text, new STextCharTypes(this, environment, text));
33
		return getDirection(expert, text, new STextCharTypes(expert, text));
34
	}
34
	}
35
35
36
	/**
36
	/**
Lines 45-52 Link Here
45
	 *          </ul>
45
	 *          </ul>
46
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
46
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
47
	 */
47
	 */
48
	public int getDirection(STextEnvironment environment, String text, STextCharTypes charTypes) {
48
	public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
49
		String language = environment.getLanguage();
49
		String language = expert.getEnvironment().getLanguage();
50
		if (!language.equals("ar")) //$NON-NLS-1$
50
		if (!language.equals("ar")) //$NON-NLS-1$
51
			return STextDirection.DIR_LTR;
51
			return STextDirection.DIR_LTR;
52
		boolean flagAN = false;
52
		boolean flagAN = false;
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java (-7 / +8 lines)
Lines 71-77 Link Here
71
	 *  
71
	 *  
72
	 *  @return the number of special cases for this handler.
72
	 *  @return the number of special cases for this handler.
73
	 */
73
	 */
74
	public int getSpecialsCount(STextEnvironment environment) {
74
	public int getSpecialsCount(ISTextExpert expert) {
75
		return maxSpecial;
75
		return maxSpecial;
76
	}
76
	}
77
77
Lines 79-85 Link Here
79
	 *  This method locates occurrences of the syntactic strings and of
79
	 *  This method locates occurrences of the syntactic strings and of
80
	 *  R, AL, EN, AN characters.
80
	 *  R, AL, EN, AN characters.
81
	 */
81
	 */
82
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
82
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
83
		// In this method, L, R, AL, AN and EN represent bidi categories
83
		// In this method, L, R, AL, AN and EN represent bidi categories
84
		// as defined in the Unicode Bidirectional Algorithm
84
		// as defined in the Unicode Bidirectional Algorithm
85
		// ( http://www.unicode.org/reports/tr9/ ).
85
		// ( http://www.unicode.org/reports/tr9/ ).
Lines 147-158 Link Here
147
	/**
147
	/**
148
	 *  This method process the special cases.
148
	 *  This method process the special cases.
149
	 */
149
	 */
150
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
150
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
151
		int location;
151
		int location;
152
152
153
		if (separLocation < 0) {
153
		if (separLocation < 0) {
154
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
154
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
155
			expert.resetState();
155
			expert.clearState();
156
		}
156
		}
157
		switch (caseNumber) {
157
		switch (caseNumber) {
158
			case 1 : /* comment (?#...) */
158
			case 1 : /* comment (?#...) */
Lines 221-228 Link Here
221
		return text.length();
221
		return text.length();
222
	}
222
	}
223
223
224
	public int getDirection(STextEnvironment environment, String text) {
224
	public int getDirection(ISTextExpert expert, String text) {
225
		return getDirection(environment, text, new STextCharTypes(this, environment, text));
225
		return getDirection(expert, text, new STextCharTypes(expert, text));
226
	}
226
	}
227
227
228
	/**
228
	/**
Lines 237-243 Link Here
237
	 *          </ul>
237
	 *          </ul>
238
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
238
	 *          Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}.
239
	 */
239
	 */
240
	public int getDirection(STextEnvironment environment, String text, STextCharTypes charTypes) {
240
	public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
241
		STextEnvironment environment = expert.getEnvironment();
241
		String language = environment.getLanguage();
242
		String language = environment.getLanguage();
242
		if (!language.equals("ar")) //$NON-NLS-1$
243
		if (!language.equals("ar")) //$NON-NLS-1$
243
			return STextDirection.DIR_LTR;
244
			return STextDirection.DIR_LTR;
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java (-5 / +4 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.bidi.internal.consumable;
11
package org.eclipse.equinox.bidi.internal.consumable;
12
12
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
15
import org.eclipse.equinox.bidi.custom.*;
14
import org.eclipse.equinox.bidi.custom.*;
16
import org.eclipse.equinox.bidi.internal.STextActivator;
15
import org.eclipse.equinox.bidi.internal.STextActivator;
17
16
Lines 47-53 Link Here
47
	/**
46
	/**
48
	 *  @return 5 as the number of special cases handled by this handler.
47
	 *  @return 5 as the number of special cases handled by this handler.
49
	 */
48
	 */
50
	public int getSpecialsCount(STextEnvironment environment) {
49
	public int getSpecialsCount(ISTextExpert expert) {
51
		return 5;
50
		return 5;
52
	}
51
	}
53
52
Lines 61-67 Link Here
61
	  *    <li>comments starting with hyphen-hyphen</li>
60
	  *    <li>comments starting with hyphen-hyphen</li>
62
	  *  </ol>
61
	  *  </ol>
63
	  */
62
	  */
64
	public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
63
	public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
65
		switch (caseNumber) {
64
		switch (caseNumber) {
66
			case 1 : /* space */
65
			case 1 : /* space */
67
				return text.indexOf(" ", fromIndex); //$NON-NLS-1$
66
				return text.indexOf(" ", fromIndex); //$NON-NLS-1$
Lines 88-100 Link Here
88
	     *    <li>skip until after a line separator</li>
87
	     *    <li>skip until after a line separator</li>
89
	     *  </ol>
88
	     *  </ol>
90
	 */
89
	 */
91
	public int processSpecial(ISTextExpert expert, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
90
	public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
92
		int location;
91
		int location;
93
92
94
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
93
		STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
95
		if (separLocation < 0) {
94
		if (separLocation < 0) {
96
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
95
			caseNumber = ((Integer) expert.getState()).intValue(); // TBD guard against "undefined"
97
			expert.resetState();
96
			expert.clearState();
98
		}
97
		}
99
		switch (caseNumber) {
98
		switch (caseNumber) {
100
			case 1 : /* space */
99
			case 1 : /* space */
(-)src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java (-2 / +2 lines)
Lines 10-16 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.equinox.bidi.internal.consumable;
11
package org.eclipse.equinox.bidi.internal.consumable;
12
12
13
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
13
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
14
import org.eclipse.equinox.bidi.internal.STextDelims;
14
import org.eclipse.equinox.bidi.internal.STextDelims;
15
15
16
/**
16
/**
Lines 25-31 Link Here
25
	/**
25
	/**
26
	 *  @return 2 as the number of special cases handled by this handler.
26
	 *  @return 2 as the number of special cases handled by this handler.
27
	 */
27
	 */
28
	public int getSpecialsCount(STextEnvironment environment) {
28
	public int getSpecialsCount(ISTextExpert expert) {
29
		return 2;
29
		return 2;
30
	}
30
	}
31
31

Return to bug 183164