diff --git src/org/eclipse/equinox/bidi/STextDirection.java src/org/eclipse/equinox/bidi/STextDirection.java index e43b4f2..9cb0156 100644 --- src/org/eclipse/equinox/bidi/STextDirection.java +++ src/org/eclipse/equinox/bidi/STextDirection.java @@ -12,7 +12,7 @@ import org.eclipse.equinox.bidi.advanced.STextEnvironment; -// TBD combine with STextUtil; remove duplicates of those two constants +// TBD combine with STextProcessor; remove duplicates of those two constants public interface STextDirection { /** diff --git src/org/eclipse/equinox/bidi/STextProcessor.java src/org/eclipse/equinox/bidi/STextProcessor.java new file mode 0 index 0000000..87d9f28 0 --- /dev/null +++ src/org/eclipse/equinox/bidi/STextProcessor.java @@ -0,0 +1,269 @@ +/******************************************************************************* + * 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; + +import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; + +/** + * This class provides a number of convenience functions facilitating the + * processing of structured text. + * + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + * + * @author Matitiahu Allouche + */ +public final class STextProcessor { + + /** + * The default set of separators used to segment a string: dot, colon, slash, backslash. + */ + public static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$ + + // left to right mark + private static final char LRM = '\u200e'; + + // left to right mark + private static final char RLM = '\u200f'; + + // left to right embedding + private static final char LRE = '\u202a'; + + // right to left embedding + private static final char RLE = '\u202b'; + + // pop directional format + private static final char PDF = '\u202c'; + + /** + * Prevents instantiation. + */ + private STextProcessor() { + // empty + } + + /** + * This method adds directional marks to the given text before the characters + * specified in the given array of offsets. It can be used to add a prefix and/or + * a suffix of directional formatting characters. + *
+ * The directional marks will be LRMs for structured text strings with LTR base + * direction and RLMs for strings with RTL base direction. + *
+ * If necessary, leading and trailing directional markers (LRE, RLE and PDF) can
+ * be added depending on the value of the affix
argument.
+ *
text
+ * before which an LRM or RLM will be inserted.
+ * The array must be sorted in ascending order without duplicates.
+ * This argument may be null
if there are no marks to add.
+ * @param direction the base direction of the structured text.
+ * It must be one of the values {@link STextDirection#DIR_LTR}, or
+ * {@link STextDirection#DIR_RTL}.
+ * @param affix specifies if a prefix and a suffix should be added to
+ * the result
+ * @return a string corresponding to the source text
with
+ * directional marks (LRMs or RLMs) added at the specified offsets,
+ * and directional formatting characters (LRE, RLE, PDF) added
+ * as prefix and suffix if so required.
+ */
+ public static String insertMarks(String text, int[] offsets, int direction, boolean affix) {
+ int textLen = text.length();
+ if (textLen == 0)
+ return ""; //$NON-NLS-1$
+
+ String curPrefix, curSuffix, full;
+ char curMark, c;
+ char[] fullChars;
+ if (direction == STextDirection.DIR_LTR) {
+ curMark = LRM;
+ curPrefix = "\u202a\u200e"; /* LRE+LRM *///$NON-NLS-1$
+ curSuffix = "\u200e\u202c"; /* LRM+PDF *///$NON-NLS-1$
+ } else {
+ curMark = RLM;
+ curPrefix = "\u202b\u200f"; /* RLE+RLM *///$NON-NLS-1$
+ curSuffix = "\u200f\u202c"; /* RLM+PDF *///$NON-NLS-1$
+ }
+ // add marks at offsets
+ if ((offsets != null) && (offsets.length > 0)) {
+ int offLen = offsets.length;
+ fullChars = new char[textLen + offLen];
+ int added = 0;
+ for (int i = 0, j = 0; i < textLen; i++) {
+ c = text.charAt(i);
+ if ((j < offLen) && (i == offsets[j])) {
+ fullChars[i + added] = curMark;
+ added++;
+ j++;
+ }
+ fullChars[i + added] = c;
+ }
+ full = new String(fullChars);
+ } else {
+ full = text;
+ }
+ if (affix)
+ return curPrefix + full + curSuffix;
+ return full;
+ }
+
+ /**
+ * Process the given text and return a string with appropriate
+ * directional formatting characters. This is equivalent to calling
+ * {@link #process(String str, String separators)} with the default
+ * set of separators.
+ * + * The processing adds directional formatting characters so that presentation + * using the Unicode Bidirectional Algorithm will provide the expected result. + * The text is segmented according to the provided separators. + * Each segment has the Unicode Bidi Algorithm applied to it, + * but as a whole, the string is oriented left to right. + *
+ * For example, a file path such as d:\myfolder\FOLDER\MYFILE.java + * (where capital letters indicate RTL text) should render as + * d:\myfolder\REDLOF\ELIFYM.java. + *
+ * @param str the text to be processed + * @return the processed string + */ + public static String process(String str) { + return process(str, defaultSeparators); + } + + /** + * Process a string that has a particular semantic meaning to render + * it correctly on bidi locales. + * @see #process(String) + * @param str the text to process + * @param separators separators by which the string will be segmented + * @return the processed string + */ + public static String process(String str, String separators) { + if ((str == null) || (str.length() <= 1)) + return str; + + // do not process a string that has already been processed. + if (str.charAt(0) == LRE && str.charAt(str.length() - 1) == PDF) + return str; + + STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); + if (!env.isProcessingNeeded()) + return str; + // do not process a string if all the following conditions are true: + // a) it has no RTL characters + // b) it starts with a LTR character + // c) it ends with a LTR character or a digit + boolean isStringBidi = false; + int strLength = str.length(); + char c; + for (int i = 0; i < strLength; i++) { + c = str.charAt(i); + if (((c >= 0x05d0) && (c <= 0x07b1)) || ((c >= 0xfb1d) && (c <= 0xfefc))) { + isStringBidi = true; + break; + } + } + while (!isStringBidi) { + if (!Character.isLetter(str.charAt(0))) + break; + c = str.charAt(strLength - 1); + if (!Character.isDigit(c) && !Character.isLetter(c)) + break; + return str; + } + + if (separators == null) + separators = defaultSeparators; + + // make sure that LRE/PDF are added around the string + STextTypeHandler handler = new STextTypeHandler(separators); + ISTextExpert expert = STextExpertFactory.getExpert(handler, env); + return expert.leanToFullText(str); + } + + /** + * Processes a string that has a particular semantic meaning to render + * it correctly on bidi locales. + * @see #process(String) + * @param str the text to process + * @param handler a handler instance appropriate for the type of the structured text + * @return the processed string + */ + public static String process(String str, STextTypeHandler handler) { + if ((str == null) || (str.length() <= 1)) + return str; + + // do not process a string that has already been processed. + char c = str.charAt(0); + if (((c == LRE) || (c == RLE)) && str.charAt(str.length() - 1) == PDF) + return str; + + // make sure that LRE/PDF are added around the string + STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); + if (!env.isProcessingNeeded()) + return str; + ISTextExpert expert = STextExpertFactory.getExpert(handler, env); + return expert.leanToFullText(str); + } + + /** + * Removes directional formatting characters in the given string. + * @param str string with directional characters to remove + * @return string without directional formatting characters + */ + public static String deprocess(String str) { + if ((str == null) || (str.length() <= 1)) + return str; + STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); + if (!env.isProcessingNeeded()) + return str; + + StringBuffer buf = new StringBuffer(); + int strLen = str.length(); + for (int i = 0; i < strLen; i++) { + char c = str.charAt(i); + switch (c) { + case LRM : + continue; + case LRE : + continue; + case PDF : + continue; + default : + buf.append(c); + } + } + return buf.toString(); + } + + /** + * Removes directional formatting characters in the given string. + * @param str string with directional characters to remove + * @param handler appropriate for the structured text + * @return string without directional formatting characters + */ + public static String deprocess(String str, STextTypeHandler handler) { + if ((str == null) || (str.length() <= 1)) + return str; + + // make sure that LRE/PDF are added around the string + STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); + if (!env.isProcessingNeeded()) + return str; + ISTextExpert expert = STextExpertFactory.getExpert(handler, env); + return expert.fullToLeanText(str); + } + +} diff --git src/org/eclipse/equinox/bidi/STextProcessorFactory.java src/org/eclipse/equinox/bidi/STextProcessorFactory.java deleted file mode 100644 index 1887b08..0000000 100644 --- src/org/eclipse/equinox/bidi/STextProcessorFactory.java +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************* - * 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; - -import org.eclipse.equinox.bidi.custom.STextProcessor; -import org.eclipse.equinox.bidi.internal.STextTypesCollector; - -/** - * This class provides access to registered structured text processors. - * - * @noinstantiate This class is not intended to be instantiated by clients. - */ -final public class STextProcessorFactory { - - /** - * Structured text processor for property file statements. It expects the following format: - *- * name=value - *- */ - public static final String PROPERTY = "property"; //$NON-NLS-1$ - - /** - * Structured text processor for compound names. It expects text to be made of one or more - * parts separated by underscores: - *
- * part1_part2_part3 - *- */ - public static final String UNDERSCORE = "underscore"; //$NON-NLS-1$ - - /** - * Structured text processor for comma-delimited lists, such as: - *
- * part1,part2,part3 - *- */ - public static final String COMMA_DELIMITED = "comma"; //$NON-NLS-1$ - - /** - * Structured text processor for strings with the following format: - *
- * system(user) - *- */ - public static final String SYSTEM_USER = "system"; //$NON-NLS-1$ - - /** - * Structured text processor for directory and file paths. - */ - public static final String FILE = "file"; //$NON-NLS-1$ - - /** - * Structured text processor for e-mail addresses. - */ - public static final String EMAIL = "email"; //$NON-NLS-1$ - - /** - * Structured text processor for URLs. - */ - public static final String URL = "url"; //$NON-NLS-1$ - - /** - * Structured text processor for regular expressions, possibly spanning multiple lines. - */ - public static final String REGEXP = "regex"; //$NON-NLS-1$ - - /** - * Structured text processor for XPath expressions. - */ - public static final String XPATH = "xpath"; //$NON-NLS-1$ - - /** - * Structured text processor for Java code, possibly spanning multiple lines. - */ - public static final String JAVA = "java"; //$NON-NLS-1$ - - /** - * Structured text processor for SQL statements, possibly spanning multiple lines. - */ - public static final String SQL = "sql"; //$NON-NLS-1$ - - /** - * Structured text processor for arithmetic expressions, possibly with a RTL base direction. - */ - public static final String RTL_ARITHMETIC = "math"; //$NON-NLS-1$ - - /** - * Prevents instantiation - */ - private STextProcessorFactory() { - // placeholder - } - - /** - * Retrieve all IDs of registered structured text processors. - * @return an array of text processor IDs. - */ - static public String[] getAllProcessorIDs() { - return STextTypesCollector.getInstance().getTypes(); - } - - /** - * Obtain a structured text processor of a given type. - * @param id string identifying processor - * @return a processor of the required type, or
null
if the type is unknown
- */
- static public STextProcessor getProcessor(String id) {
- return STextTypesCollector.getInstance().getProcessor(id);
- }
-
-}
diff --git src/org/eclipse/equinox/bidi/STextStringRecord.java src/org/eclipse/equinox/bidi/STextStringRecord.java
index f28bd6b..60d48d8 100644
--- src/org/eclipse/equinox/bidi/STextStringRecord.java
+++ src/org/eclipse/equinox/bidi/STextStringRecord.java
@@ -25,7 +25,7 @@
* A string may be itself entirely a structured text, or it may contain
* segments each of which is a structured text of a given type. Each such
* segment is identified by its starting and ending offsets within the
- * string, and by the processor which is appropriate to handle it.
+ * string, and by the handler which is appropriate to handle it.
*/
public class STextStringRecord {
/**
@@ -57,8 +57,8 @@
// reference to the recorded string
private String string;
- // reference to the processors of the STT segments in the recorded string
- private String[] processors;
+ // reference to the handlers of the STT segments in the recorded string
+ private String[] handlers;
// reference to the boundaries of the STT segments in the recorded string
// (entries 0, 2, 4, ... are start offsets; entries 1, 3, 5, ... are
@@ -74,7 +74,7 @@
/**
* Record a string in the pool. The caller must specify the number
- * of segments in the record (at least 1), and the processor, starting
+ * of segments in the record (at least 1), and the handler, starting
* and ending offsets for the first segment.
*
* @param string the string to record.
@@ -82,9 +82,9 @@
* @param segmentCount number of segments allowed in this string.
* This number must be >= 1.
*
- * @param processor the processor appropriate to handle the type
+ * @param handler the handler appropriate to handle the type
* of structured text present in the first segment.
- * It may be one of the pre-defined processor instances, or it may be an instance
+ * It may be one of the pre-defined handler instances, or it may be an instance
* created by a plug-in or by the application.
*
* @param start offset in the string of the starting character of the first
@@ -102,7 +102,7 @@
* if segmentCount
is less than 1.
* @throws also the same exceptions as {@link #addSegment addSegment}.
*/
- public static STextStringRecord addRecord(String string, int segmentCount, String processorID, int start, int limit) {
+ public static STextStringRecord addRecord(String string, int segmentCount, String handlerID, int start, int limit) {
if (string == null)
throw new IllegalArgumentException("The string argument must not be null!"); //$NON-NLS-1$
if (segmentCount < 1)
@@ -124,24 +124,24 @@
}
hashArray[last] = string.hashCode();
for (int i = 0; i < record.usedSegmentCount; i++)
- record.processors[i] = null;
+ record.handlers[i] = null;
if (segmentCount > record.totalSegmentCount) {
- record.processors = new String[segmentCount];
+ record.handlers = new String[segmentCount];
record.boundaries = new short[segmentCount * 2];
record.totalSegmentCount = segmentCount;
}
record.usedSegmentCount = 0;
record.string = string;
- record.addSegment(processorID, start, limit);
+ record.addSegment(handlerID, start, limit);
return record;
}
/**
* Add a second or further segment to a record.
*
- * @param processor the processor appropriate to handle the type
+ * @param handler the handler appropriate to handle the type
* of structured text present in this segment.
- * It may be one of the pre-defined processor instances, or it may be an instance
+ * It may be one of the pre-defined handler instances, or it may be an instance
* created by a plug-in or by the application.
*
* @param start offset in the string of the starting character of the
@@ -151,7 +151,7 @@
* greater than the start
argument and not greater
* than the length of the string.
*
- * @throws IllegalArgumentException if processor
is null,
+ * @throws IllegalArgumentException if handler
is null,
* or if start
or limit
have invalid
* values.
* @throws IllegalStateException if the current segment exceeds the
@@ -159,16 +159,16 @@
* in the call to {@link #addRecord addRecord} which created
* the STextStringRecord instance.
*/
- public void addSegment(String processorID, int start, int limit) {
- if (processorID == null)
- throw new IllegalArgumentException("The processor argument must not be null!"); //$NON-NLS-1$
+ public void addSegment(String handlerID, int start, int limit) {
+ if (handlerID == null)
+ throw new IllegalArgumentException("The handler argument must not be null!"); //$NON-NLS-1$
if (start < 0 || start >= string.length())
throw new IllegalArgumentException("The start position must be at least 0 and less than the length of the string!"); //$NON-NLS-1$
if (limit <= start || limit > string.length())
throw new IllegalArgumentException("The limit position must be greater than the start position but no greater than the length of the string!"); //$NON-NLS-1$
if (usedSegmentCount >= totalSegmentCount)
throw new IllegalStateException("All segments of the record are already used!"); //$NON-NLS-1$
- processors[usedSegmentCount] = processorID;
+ handlers[usedSegmentCount] = handlerID;
boundaries[usedSegmentCount * 2] = (short) start;
boundaries[usedSegmentCount * 2 + 1] = (short) limit;
usedSegmentCount++;
@@ -184,8 +184,8 @@
* records this string.segmentNumber
.
*
* @throws IllegalArgumentException if segmentNumber
@@ -252,9 +252,9 @@
*
* @see #getSegmentCount
*/
- public String getProcessor(int segmentNumber) {
+ public String getHandler(int segmentNumber) {
checkSegmentNumber(segmentNumber);
- return processors[segmentNumber];
+ return handlers[segmentNumber];
}
/**
@@ -315,7 +315,7 @@
if (record == null)
continue;
record.boundaries = null;
- record.processors = null;
+ record.handlers = null;
record.totalSegmentCount = 0;
record.usedSegmentCount = 0;
recordRefs[i].clear();
diff --git src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java
new file mode 0
index 0000000..8525b9b 0
--- /dev/null
+++ src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.equinox.bidi.custom.STextTypeHandler;
+import org.eclipse.equinox.bidi.internal.STextTypesCollector;
+
+/**
+ * This class provides access to registered structured text handlers.
+ *
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ */
+final public class STextTypeHandlerFactory {
+
+ /**
+ * Structured text handler for property file statements. It expects the following format:
+ * + * name=value + *+ */ + public static final String PROPERTY = "property"; //$NON-NLS-1$ + + /** + * Structured text handler for compound names. It expects text to be made of one or more + * parts separated by underscores: + *
+ * part1_part2_part3 + *+ */ + public static final String UNDERSCORE = "underscore"; //$NON-NLS-1$ + + /** + * Structured text handler for comma-delimited lists, such as: + *
+ * part1,part2,part3 + *+ */ + public static final String COMMA_DELIMITED = "comma"; //$NON-NLS-1$ + + /** + * Structured text handler for strings with the following format: + *
+ * system(user) + *+ */ + public static final String SYSTEM_USER = "system"; //$NON-NLS-1$ + + /** + * Structured text handler for directory and file paths. + */ + public static final String FILE = "file"; //$NON-NLS-1$ + + /** + * Structured text handler for e-mail addresses. + */ + public static final String EMAIL = "email"; //$NON-NLS-1$ + + /** + * Structured text handler for URLs. + */ + public static final String URL = "url"; //$NON-NLS-1$ + + /** + * Structured text handler for regular expressions, possibly spanning multiple lines. + */ + public static final String REGEXP = "regex"; //$NON-NLS-1$ + + /** + * Structured text handler for XPath expressions. + */ + public static final String XPATH = "xpath"; //$NON-NLS-1$ + + /** + * Structured text handler for Java code, possibly spanning multiple lines. + */ + public static final String JAVA = "java"; //$NON-NLS-1$ + + /** + * Structured text handler for SQL statements, possibly spanning multiple lines. + */ + public static final String SQL = "sql"; //$NON-NLS-1$ + + /** + * Structured text handler for arithmetic expressions, possibly with a RTL base direction. + */ + public static final String RTL_ARITHMETIC = "math"; //$NON-NLS-1$ + + /** + * Prevents instantiation + */ + private STextTypeHandlerFactory() { + // placeholder + } + + /** + * Retrieve all IDs of registered structured text handlers. + * @return an array of text handler IDs. + */ + static public String[] getAllHandlerIDs() { + return STextTypesCollector.getInstance().getTypes(); + } + + /** + * Obtain a structured text handler of a given type. + * @param id string identifying handler + * @return a handler of the required type, or
null
if the type is unknown
+ */
+ static public STextTypeHandler getHandler(String id) {
+ return STextTypesCollector.getInstance().getHandler(id);
+ }
+
+}
diff --git src/org/eclipse/equinox/bidi/STextUtil.java src/org/eclipse/equinox/bidi/STextUtil.java
deleted file mode 100644
index a98e8e9..0000000 100644
--- src/org/eclipse/equinox/bidi/STextUtil.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import org.eclipse.equinox.bidi.advanced.*;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
-
-/**
- * This class provides a number of convenience functions facilitating the
- * processing of structured text.
- *
- * @noextend This class is not intended to be subclassed by clients.
- * @noinstantiate This class is not intended to be instantiated by clients.
- *
- * @author Matitiahu Allouche
- */
-public final class STextUtil {
-
- /**
- * The default set of separators used to segment a string: dot, colon, slash, backslash.
- */
- public static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$
-
- // left to right mark
- private static final char LRM = '\u200e';
-
- // left to right mark
- private static final char RLM = '\u200f';
-
- // left to right embedding
- private static final char LRE = '\u202a';
-
- // right to left embedding
- private static final char RLE = '\u202b';
-
- // pop directional format
- private static final char PDF = '\u202c';
-
- /**
- * Prevents instantiation.
- */
- private STextUtil() {
- // empty
- }
-
- /**
- * This method adds directional marks to the given text before the characters
- * specified in the given array of offsets. It can be used to add a prefix and/or
- * a suffix of directional formatting characters.
- * - * The directional marks will be LRMs for structured text strings with LTR base - * direction and RLMs for strings with RTL base direction. - *
- * If necessary, leading and trailing directional markers (LRE, RLE and PDF) can
- * be added depending on the value of the affix
argument.
- *
text
- * before which an LRM or RLM will be inserted.
- * The array must be sorted in ascending order without duplicates.
- * This argument may be null
if there are no marks to add.
- * @param direction the base direction of the structured text.
- * It must be one of the values {@link STextDirection#DIR_LTR}, or
- * {@link STextDirection#DIR_RTL}.
- * @param affix specifies if a prefix and a suffix should be added to
- * the result
- * @return a string corresponding to the source text
with
- * directional marks (LRMs or RLMs) added at the specified offsets,
- * and directional formatting characters (LRE, RLE, PDF) added
- * as prefix and suffix if so required.
- */
- public static String insertMarks(String text, int[] offsets, int direction, boolean affix) {
- int textLen = text.length();
- if (textLen == 0)
- return ""; //$NON-NLS-1$
-
- String curPrefix, curSuffix, full;
- char curMark, c;
- char[] fullChars;
- if (direction == STextDirection.DIR_LTR) {
- curMark = LRM;
- curPrefix = "\u202a\u200e"; /* LRE+LRM *///$NON-NLS-1$
- curSuffix = "\u200e\u202c"; /* LRM+PDF *///$NON-NLS-1$
- } else {
- curMark = RLM;
- curPrefix = "\u202b\u200f"; /* RLE+RLM *///$NON-NLS-1$
- curSuffix = "\u200f\u202c"; /* RLM+PDF *///$NON-NLS-1$
- }
- // add marks at offsets
- if ((offsets != null) && (offsets.length > 0)) {
- int offLen = offsets.length;
- fullChars = new char[textLen + offLen];
- int added = 0;
- for (int i = 0, j = 0; i < textLen; i++) {
- c = text.charAt(i);
- if ((j < offLen) && (i == offsets[j])) {
- fullChars[i + added] = curMark;
- added++;
- j++;
- }
- fullChars[i + added] = c;
- }
- full = new String(fullChars);
- } else {
- full = text;
- }
- if (affix)
- return curPrefix + full + curSuffix;
- return full;
- }
-
- /**
- * Process the given text and return a string with appropriate
- * directional formatting characters. This is equivalent to calling
- * {@link #process(String str, String separators)} with the default
- * set of separators.
- * - * The processing adds directional formatting characters so that presentation - * using the Unicode Bidirectional Algorithm will provide the expected result. - * The text is segmented according to the provided separators. - * Each segment has the Unicode Bidi Algorithm applied to it, - * but as a whole, the string is oriented left to right. - *
- * For example, a file path such as d:\myfolder\FOLDER\MYFILE.java - * (where capital letters indicate RTL text) should render as - * d:\myfolder\REDLOF\ELIFYM.java. - *
- * @param str the text to be processed - * @return the processed string - */ - public static String process(String str) { - return process(str, defaultSeparators); - } - - /** - * Process a string that has a particular semantic meaning to render - * it correctly on bidi locales. - * @see #process(String) - * @param str the text to process - * @param separators separators by which the string will be segmented - * @return the processed string - */ - public static String process(String str, String separators) { - if ((str == null) || (str.length() <= 1)) - return str; - - // do not process a string that has already been processed. - if (str.charAt(0) == LRE && str.charAt(str.length() - 1) == PDF) - return str; - - STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); - if (!env.isProcessingNeeded()) - return str; - // do not process a string if all the following conditions are true: - // a) it has no RTL characters - // b) it starts with a LTR character - // c) it ends with a LTR character or a digit - boolean isStringBidi = false; - int strLength = str.length(); - char c; - for (int i = 0; i < strLength; i++) { - c = str.charAt(i); - if (((c >= 0x05d0) && (c <= 0x07b1)) || ((c >= 0xfb1d) && (c <= 0xfefc))) { - isStringBidi = true; - break; - } - } - while (!isStringBidi) { - if (!Character.isLetter(str.charAt(0))) - break; - c = str.charAt(strLength - 1); - if (!Character.isDigit(c) && !Character.isLetter(c)) - break; - return str; - } - - if (separators == null) - separators = defaultSeparators; - - // make sure that LRE/PDF are added around the string - STextProcessor processor = new STextProcessor(separators); - ISTextExpert processorNew = STextExpertFactory.getExpert(processor, env); - return processorNew.leanToFullText(str); - } - - /** - * Processes a string that has a particular semantic meaning to render - * it correctly on bidi locales. - * @see #process(String) - * @param str the text to process - * @param processor a processor instance appropriate for the type of the structured text - * @return the processed string - */ - public static String process(String str, STextProcessor processor) { - if ((str == null) || (str.length() <= 1)) - return str; - - // do not process a string that has already been processed. - char c = str.charAt(0); - if (((c == LRE) || (c == RLE)) && str.charAt(str.length() - 1) == PDF) - return str; - - // make sure that LRE/PDF are added around the string - STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); - if (!env.isProcessingNeeded()) - return str; - ISTextExpert processorNew = STextExpertFactory.getExpert(processor, env); - return processorNew.leanToFullText(str); - } - - /** - * Removes directional formatting characters in the given string. - * @param str string with directional characters to remove - * @return string without directional formatting characters - */ - public static String deprocess(String str) { - if ((str == null) || (str.length() <= 1)) - return str; - STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); - if (!env.isProcessingNeeded()) - return str; - - StringBuffer buf = new StringBuffer(); - int strLen = str.length(); - for (int i = 0; i < strLen; i++) { - char c = str.charAt(i); - switch (c) { - case LRM : - continue; - case LRE : - continue; - case PDF : - continue; - default : - buf.append(c); - } - } - return buf.toString(); - } - - /** - * Removes directional formatting characters in the given string. - * @param str string with directional characters to remove - * @param processor appropriate for the structured text - * @return string without directional formatting characters - */ - public static String deprocess(String str, STextProcessor processor) { - if ((str == null) || (str.length() <= 1)) - return str; - - // make sure that LRE/PDF are added around the string - STextEnvironment env = new STextEnvironment(null, false, STextEnvironment.ORIENT_UNKNOWN); - if (!env.isProcessingNeeded()) - return str; - ISTextExpert processorNew = STextExpertFactory.getExpert(processor, env); - return processorNew.fullToLeanText(str); - } - -} diff --git src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java index 996be6e..e1b986f 100644 --- src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java +++ src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java @@ -14,10 +14,10 @@ * For a general introduction to structured text, see * {@link the package documentation}. *- * Several common processors are included in STextEngine. For processors - * supplied by other packages, a processor instance can be obtained using the - * {@link org.eclipse.equinox.bidi.STextProcessorFactory#getProcessor} - * method for the registered processors, or by instantiating a private processor. + * Several common handlers are included in STextEngine. For handlers + * supplied by other packages, a handler instance can be obtained using the + * {@link org.eclipse.equinox.bidi.STextTypeHandlerFactory#getHandler} + * method for the registered handlers, or by instantiating a private handler. *
* Most of the methods in this class have a text
* argument which may be just a part of a larger body of text.
@@ -100,7 +100,7 @@
* Add directional formatting characters to a structured text
* to ensure correct presentation.
*
- * @param processor the processor applicable to the text. If null
,
+ * @param handler the handler applicable to the text. If null
,
* the method returns unmodified text.
*
* @param environment a bidi environment. If null
, the default environment
@@ -122,11 +122,11 @@
* Given a lean string, compute the positions of each of its
* characters within the corresponding full string.
*
- * @param processor designates a processor instance. If null
, this
+ * @param handler designates a handler instance. If null
, this
* method returns an identity map.
*
* @param environment specifies an environment whose characteristics may affect
- * the processor's behavior. If null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string.
*
@@ -151,10 +151,10 @@
* depending on the {@link STextEnvironment#getOrientation orientation} of the
* GUI component used for display are not reflected in this method.
*
null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string
*
@@ -173,10 +173,10 @@
* Remove directional formatting characters which were added to a
* structured text string to ensure correct presentation.
*
- * @param processor designates a processor instance
+ * @param handler designates a handler instance
*
* @param environment specifies an environment whose characteristics may affect
- * the processor's behavior. If null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string including directional formatting characters.
*
@@ -195,10 +195,10 @@
* Given a full string, compute the positions of each of its
* characters within the corresponding lean string.
*
- * @param processor designates a processor instance
+ * @param handler designates a handler instance
*
* @param environment specifies an environment whose characteristics may affect
- * the processor's behavior. If null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string including directional formatting characters.
*
@@ -225,10 +225,10 @@
* or suffixed depending on the {@link STextEnvironment#getOrientation orientation}
* of the GUI component used for display.
*
- * @param processor designates a processor instance
+ * @param handler designates a handler instance
*
* @param environment specifies an environment whose characteristics may affect
- * the processor's behavior. If null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string including directional formatting characters
*
@@ -248,10 +248,10 @@
* whether the text contains Arabic or Hebrew words. If the text contains both,
* the first Arabic or Hebrew letter in the text determines which is the governing script.
*
- * @param processor designates a processor instance
+ * @param handler designates a handler instance
*
* @param environment specifies an environment whose characteristics may affect
- * the processor's behavior. If null
, the default environment is used.
+ * the handler's behavior. If null
, the default environment is used.
*
* @param text is the structured text string
*
diff --git src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java
index f69a48f..cebf2fd 100644
--- src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java
+++ src/org/eclipse/equinox/bidi/advanced/ISTextExpertStateful.java
@@ -17,7 +17,7 @@
public int getState();
/**
- * Resets non-shared processor state to initial.
+ * Resets non-shared expert state to initial.
*/
public void resetState();
diff --git src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
index 3518830..220de73 100644
--- src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
+++ src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
@@ -12,10 +12,9 @@
import java.util.HashMap;
import java.util.Map;
-import org.eclipse.equinox.bidi.STextProcessorFactory;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
-import org.eclipse.equinox.bidi.internal.STextExpertImpl;
-import org.eclipse.equinox.bidi.internal.STextExpertMultipassImpl;
+import org.eclipse.equinox.bidi.STextTypeHandlerFactory;
+import org.eclipse.equinox.bidi.custom.STextTypeHandler;
+import org.eclipse.equinox.bidi.internal.STextImpl;
final public class STextExpertFactory {
@@ -36,49 +35,49 @@
static public ISTextExpert getExpert() {
if (defaultExpert == null) {
- STextProcessor descriptor = new STextProcessor(defaultSeparators);
- defaultExpert = new STextExpertImpl(descriptor, STextEnvironment.DEFAULT);
+ STextTypeHandler handler = new STextTypeHandler(defaultSeparators);
+ defaultExpert = new STextImpl(handler, STextEnvironment.DEFAULT, null);
}
return defaultExpert;
}
static public ISTextExpert getExpert(String type) {
- ISTextExpert processor;
+ ISTextExpert expert;
synchronized (sharedDefaultExperts) {
- processor = (ISTextExpert) sharedDefaultExperts.get(type);
- if (processor == null) {
- STextProcessor descriptor = STextProcessorFactory.getProcessor(type);
- if (descriptor == null)
+ expert = (ISTextExpert) sharedDefaultExperts.get(type);
+ if (expert == null) {
+ STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
+ if (handler == null)
return null;
- processor = new STextExpertImpl(descriptor, STextEnvironment.DEFAULT);
- sharedDefaultExperts.put(type, processor);
+ expert = new STextImpl(handler, STextEnvironment.DEFAULT, null);
+ sharedDefaultExperts.put(type, expert);
}
}
- return processor;
+ return expert;
}
static public ISTextExpert getExpert(String type, STextEnvironment environment) {
- ISTextExpert processor;
+ ISTextExpert expert;
synchronized (sharedExperts) {
- Map processors = (Map) sharedExperts.get(type);
- if (processors == null) {
- processors = new HashMap(); // environment -> processor
- sharedExperts.put(type, processors);
+ Map experts = (Map) sharedExperts.get(type);
+ if (experts == null) {
+ experts = new HashMap(); // environment -> expert
+ sharedExperts.put(type, experts);
}
- processor = (ISTextExpert) processors.get(environment);
- if (processor == null) {
- STextProcessor descriptor = STextProcessorFactory.getProcessor(type);
- if (descriptor == null)
+ expert = (ISTextExpert) experts.get(environment);
+ if (expert == null) {
+ STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
+ if (handler == null)
return null;
- processor = new STextExpertImpl(descriptor, environment);
- processors.put(type, processor);
+ expert = new STextImpl(handler, environment, null);
+ experts.put(type, expert);
}
}
- return processor;
+ return expert;
}
- static public ISTextExpert getExpert(STextProcessor descriptor, STextEnvironment environment) {
- return new STextExpertImpl(descriptor, environment);
+ static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) {
+ return new STextImpl(handler, environment, new int[1]);
}
static public ISTextExpertStateful getPrivateExpert(String type) {
@@ -86,10 +85,10 @@
}
static public ISTextExpertStateful getPrivateExpert(String type, STextEnvironment environment) {
- STextProcessor descriptor = STextProcessorFactory.getProcessor(type);
- if (descriptor == null)
+ STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
+ if (handler == null)
return null;
- return new STextExpertMultipassImpl(descriptor, environment);
+ return new STextImpl(handler, environment, new int[1]);
}
}
diff --git src/org/eclipse/equinox/bidi/custom/STextCharTypes.java src/org/eclipse/equinox/bidi/custom/STextCharTypes.java
index f74bd7b..ba1f0b7 100644
--- src/org/eclipse/equinox/bidi/custom/STextCharTypes.java
+++ src/org/eclipse/equinox/bidi/custom/STextCharTypes.java
@@ -35,32 +35,32 @@
private static final int CHARTYPES_ADD = 2;
- final protected STextProcessor processor;
+ final protected STextTypeHandler handler;
final protected STextEnvironment environment;
final protected String text;
// 1 byte for each char in text
private byte[] types;
- // structured text direction. -1 means not yet computed; -2 means within processor.getDirection
+ // structured text direction. -1 means not yet computed; -2 means within handler.getDirection
private int direction = -1;
/**
* Constructor
*
- * @param processor is the processor handling this occurrence of
+ * @param handler is the handler handling this occurrence of
* structured text.
*
* @param environment the current environment, which may affect the behavior of
- * the processor. This parameter may be specified as
+ * the handler. This parameter may be specified as
* null
, in which case the
* {@link STextEnvironment#DEFAULT DEFAULT}
* environment should be assumed.
*
* @param text is the text whose characters are analyzed.
*/
- public STextCharTypes(STextProcessor processor, STextEnvironment environment, String text) {
- this.processor = processor;
+ public STextCharTypes(STextTypeHandler handler, STextEnvironment environment, String text) {
+ this.handler = handler;
this.environment = environment;
this.text = text;
types = new byte[text.length()];
@@ -68,7 +68,7 @@
public int getDirection() {
if (direction < 0)
- direction = processor.getDirection(environment, text, this);
+ direction = handler.getDirection(environment, text, this);
return direction;
}
@@ -96,10 +96,10 @@
byte charType = Character.getDirectionality(text.charAt(index));
if (charType == B) {
if (direction < 0) {
- if (direction < -1) // called by processor.getDirection
+ if (direction < -1) // called by handler.getDirection
return charType; // avoid infinite recursion
- direction = -2; // signal we go within processor.getDirection
- direction = processor.getDirection(environment, text, this);
+ direction = -2; // signal we go within handler.getDirection
+ direction = handler.getDirection(environment, text, this);
}
charType = (direction == STextEnvironment.ORIENT_RTL) ? R : L;
}
@@ -125,7 +125,7 @@
* be displayed.
*
* @param envir is the current environment, which may affect the behavior of
- * the processor. This parameter may be specified as
+ * the handler. This parameter may be specified as
* null
, in which case the
* {@link STextEnvironment#DEFAULT DEFAULT}
* environment should be assumed.
diff --git src/org/eclipse/equinox/bidi/custom/STextOffsets.java src/org/eclipse/equinox/bidi/custom/STextOffsets.java
index 5358ad5..4ac9270 100644
--- src/org/eclipse/equinox/bidi/custom/STextOffsets.java
+++ src/org/eclipse/equinox/bidi/custom/STextOffsets.java
@@ -67,7 +67,7 @@
/**
* Insert an offset value in the offset array so that the array
* stays in ascending order.
- * @param procData is a group of data accessible to processors.
+ * @param procData is a group of data accessible to handlers.
* @param offset is the value to insert.
*/
public void insertOffset(STextCharTypes charTypes, int offset) {
diff --git src/org/eclipse/equinox/bidi/custom/STextProcessor.java src/org/eclipse/equinox/bidi/custom/STextProcessor.java
deleted file mode 100644
index e760eff..0000000 100644
--- src/org/eclipse/equinox/bidi/custom/STextProcessor.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*******************************************************************************
- * 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.custom;
-
-import org.eclipse.equinox.bidi.STextDirection;
-import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.internal.STextImpl;
-
-/**
- * Generic processor to be used as superclass (base class)
- * for specific structured text processors.
- * - * Here are some guidelines about how to write structured text - * processors. - *
- * This method is called repeatedly if the number of special cases - * returned by {@link #getSpecialsCount} is greater than zero. - *
- * A processor handling special cases must override this method. - *
- * @param environment the current environment, which may affect the behavior of - * the processor. This parameter may be specified as - *null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @param text is the structured text string before
- * addition of any directional formatting characters.
- *
- * @param charTypes is a parameter received by indexOfSpecial
- * uniquely to be used as argument for calls to methods which
- * need it.
- *
- * @param offsets is a parameter received by indexOfSpecial
- * uniquely to be used as argument for calls to methods which
- * need it.
- *
- * @param caseNumber number of the special case to locate.
- * This number varies from 1 to the number of special cases
- * returned by {@link #getSpecialsCount getSpecialsCount}
- * for this processor.
- * The meaning of this number is internal to the class
- * implementing indexOfSpecial
.
- *
- * @param fromIndex the index within text
to start
- * the search from.
- *
- * @return the position where the start of the special case
- * corresponding to caseNumber
was located.
- * The method must return the first occurrence of whatever
- * identifies the start of the special case starting from
- * fromIndex
. The method does not have to check if
- * this occurrence appears within the scope of another special
- * case (e.g. a comment starting delimiter within the scope of
- * a literal or vice-versa).
- * IllegalStateException
. This is appropriate behavior
- * (and does not need to be overridden) for processors whose
- * number of special cases is zero, which means that
- * indexOfSpecial
should never be called for them.
- */
- public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
- // This method must be overridden by all subclasses with special cases.
- throw new IllegalStateException("A processor with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$
- }
-
- /**
- * This method handles special cases specific to this processor.
- * It is called when a special case occurrence
- * is located by {@link #indexOfSpecial}.
- *
- * If a special processing cannot be completed within a current call to
- * processSpecial
(for instance, a comment has been started
- * in the current line but its end appears in a following line),
- * processSpecial
should specify a final state by
- * putting its value in the first element of the state
- * parameter.
- * The meaning of this state is internal to the processor.
- * On a later call, processSpecial
will be called with that value
- * for parameter caseNumber
and -1
for parameter
- * separLocation
and should perform whatever initializations are required
- * depending on the state.
- *
- * A processor handling special cases (with a number of - * special cases greater than zero) must override this method. - *
- * @param environment the current environment, which may affect the behavior of - * the processor. This parameter may be specified as - *null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @param text is the structured text string before
- * addition of any directional formatting characters.
- *
- * @param charTypes is a parameter received by processSpecial
- * uniquely to be used as argument for calls to methods which
- * need it.
- *
- * @param offsets is a parameter received by processSpecial
- * uniquely to be used as argument for calls to methods which
- * need it.
- *
- * @param state is an integer array with at least one element.
- * If the processor needs to signal the occurrence of a
- * special case which must be passed to the next call to
- * leanToFullText
(for instance, a comment or a
- * literal started but not closed in the current
- * text
), it must put a value in the first element
- * of the state
parameter.
- * This number must be >= 1 and less or equal to the number of special
- * cases returned by {@link #getSpecialsCount getSpecialsCount}
- * by this processor.
- * This number is passed back to the caller
- * and should be specified as state
argument
- * in the next call to leanToFullText
together
- * with the continuation text.
- * The meaning of this number is internal to the processor.
- *
- * @param caseNumber number of the special case to handle.
- *
- * @param separLocation the position returned by
- * {@link #indexOfSpecial indexOfSpecial}. In calls to
- * {@link ISTextExpert#leanToFullText leanToFullText} and other
- * methods of {@link ISTextExpert} specifying a non-null
- * state
parameter, processSpecial
is
- * called when initializing the processing with the value of
- * caseNumber
equal to the value returned in the
- * first element of state
and the value of
- * separLocation
equal to -1
.
- *
- * @return the position after the scope of the special case ends.
- * For instance, the position after the end of a comment,
- * the position after the end of a literal.
- * text
- * means that there is no further occurrence of this case in the
- * current structured text.
- *
- * @throws IllegalStateException If not overridden, this method throws an
- * IllegalStateException
. This is appropriate behavior
- * (and does not need to be overridden) for processors whose
- * number of special cases is zero, which means that
- * processSpecial
should never be called for them.
- */
- public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) {
- // This method must be overridden by all subclasses with any special case.
- throw new IllegalStateException("A processor with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$
- }
-
- /**
- * This method can be called from within {@link #indexOfSpecial} or
- * {@link #processSpecial} in extensions of STextProcessor
- * to specify that a mark character must be added before the character
- * at the specified position of the lean text when generating the
- * full text. The mark character will be LRM for structured text
- * with a LTR base direction, and RLM for structured text with RTL
- * base direction. The mark character is not added physically by this
- * method, but its position is noted and will be used when generating
- * the full text.
- *
- * @param text is the structured text string received as
- * parameter to indexOfSpecial
or
- * processSpecial
.
- *
- * @param charTypes is a parameter received by indexOfSpecial
- * or processSpecial
, uniquely to be used as argument
- * for calls to insertMark
and other methods used
- * by processors.
- *
- * @param offsets is a parameter received by indexOfSpecial
- * or processSpecial
, uniquely to be used as argument
- * for calls to insertMark
and other methods used
- * by processors.
- *
- * @param offset position of the character in the lean text.
- * It must be a non-negative number smaller than the length
- * of the lean text.
- * For the benefit of efficiency, it is better to insert
- * multiple marks in ascending order of the offsets.
- */
- public static final void insertMark(String text, STextCharTypes charTypes, STextOffsets offsets, int offset) {
- offsets.insertOffset(charTypes, offset);
- }
-
- /**
- * This method can be called from within {@link #indexOfSpecial} or
- * {@link #processSpecial} in extensions of STextProcessor
to add
- * a directional mark before a separator if needed for correct display,
- * depending on the base direction of the text and on the class of the
- * characters in the lean text preceding and following the separator itself.
- *
- * The logic implemented in this method considers the text before
- * separLocation
and the text following it. If, and only if,
- * a directional mark is needed to insure that the two parts of text
- * will be laid out according to the base direction, a mark will be
- * added when generating the full text.
- *
indexOfSpecial
or
- * processSpecial
.
- *
- * @param charTypes is a parameter received by indexOfSpecial
- * or processSpecial
, uniquely to be used as argument
- * for calls to processSeparator
and other methods used
- * by processors.
- *
- * @param offsets is a parameter received by indexOfSpecial
- * or processSpecial
, uniquely to be used as argument
- * for calls to processSeparator
and other methods used
- * by processors.
- *
- * @param separLocation offset of the separator in the lean text.
- * It must be a non-negative number smaller than the length
- * of the lean text.
- */
- public static final void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation) {
- STextImpl.processSeparator(text, charTypes, offsets, separLocation);
- }
-
- /**
- * Indicate the separators to use for the current processor.
- * This method is invoked before starting the processing.
- * - * If no separators are specified, this method returns an empty string. - *
- * @param environment the current environment, which may affect the behavior of - * the processor. This parameter may be specified as - *null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @return a string grouping one-character separators which separate
- * the structured text into tokens.
- */
- public String getSeparators(STextEnvironment environment) {
- return separators;
- }
-
- /**
- * Indicate the base text direction appropriate for an instance of structured text.
- * This method is invoked before starting the processing.
- *
- * If not overridden, this method returns DIR_LTR
.
- *
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @param text is the structured text string to process.
- *
- * @return the base direction of the structured text. This direction
- * may not be the same depending on the environment and on
- * whether the structured text contains Arabic or Hebrew
- * letters.
- * If not overridden, this method returns DIR_LTR
.
- *
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @param text is the structured text string to process.
- *
- * @param charTypes is a parameter received uniquely to be used as argument
- * for calls to getCharType
and other methods used
- * by processors.
- *
- * @return the base direction of the structured text. This direction
- * may not be the same depending on the environment and on
- * whether the structured text contains Arabic or Hebrew
- * letters.
- * If not overridden, this method returns zero
.
- *
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @return the number of special cases for the associated processor.
- * Special cases exist for some types of structured text
- * processors. They are implemented by overriding methods
- * {@link STextProcessor#indexOfSpecial} and {@link STextProcessor#processSpecial}.
- * Examples of special cases are comments, literals, or
- * anything which is not identified by a one-character separator.
- *
- */
- public int getSpecialsCount(STextEnvironment environment) {
- return 0;
- }
-
- /**
- * Checks if there is a need for processing structured text.
- * This method is invoked before starting the processing. If the
- * processor returns true
, no directional formatting
- * characters are added to the lean text and the processing
- * is shortened.
- *
- * If not overridden, this method returns false
.
- *
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
- *
- * @param text is the structured text string to process.
- *
- * @param charTypes is a parameter received uniquely to be used as argument
- * for calls to getCharType
and other methods used
- * by processors.
- *
- * @return a flag indicating if there is no need to process the structured
- * text to add directional formatting characters.
- *
- */
- public boolean skipProcessing(STextEnvironment environment, String text, STextCharTypes charTypes) {
- return false;
- }
-
-}
diff --git src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java
new file mode 0
index 0000000..993033e 0
--- /dev/null
+++ src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java
@@ -0,0 +1,416 @@
+/*******************************************************************************
+ * 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.custom;
+
+import org.eclipse.equinox.bidi.STextDirection;
+import org.eclipse.equinox.bidi.advanced.ISTextExpert;
+import org.eclipse.equinox.bidi.advanced.STextEnvironment;
+import org.eclipse.equinox.bidi.internal.STextImpl;
+
+/**
+ * Generic handler to be used as superclass (base class)
+ * for specific structured text handlers.
+ * + * Here are some guidelines about how to write structured text + * handlers. + *
+ * This method is called repeatedly if the number of special cases + * returned by {@link #getSpecialsCount} is greater than zero. + *
+ * A handler handling special cases must override this method. + *
+ * @param environment the current environment, which may affect the behavior of + * the handler. This parameter may be specified as + *null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @param text is the structured text string before
+ * addition of any directional formatting characters.
+ *
+ * @param charTypes is a parameter received by indexOfSpecial
+ * uniquely to be used as argument for calls to methods which
+ * need it.
+ *
+ * @param offsets is a parameter received by indexOfSpecial
+ * uniquely to be used as argument for calls to methods which
+ * need it.
+ *
+ * @param caseNumber number of the special case to locate.
+ * This number varies from 1 to the number of special cases
+ * returned by {@link #getSpecialsCount getSpecialsCount}
+ * for this handler.
+ * The meaning of this number is internal to the class
+ * implementing indexOfSpecial
.
+ *
+ * @param fromIndex the index within text
to start
+ * the search from.
+ *
+ * @return the position where the start of the special case
+ * corresponding to caseNumber
was located.
+ * The method must return the first occurrence of whatever
+ * identifies the start of the special case starting from
+ * fromIndex
. The method does not have to check if
+ * this occurrence appears within the scope of another special
+ * case (e.g. a comment starting delimiter within the scope of
+ * a literal or vice-versa).
+ * IllegalStateException
. This is appropriate behavior
+ * (and does not need to be overridden) for handlers whose
+ * number of special cases is zero, which means that
+ * indexOfSpecial
should never be called for them.
+ */
+ public int indexOfSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
+ // This method must be overridden by all subclasses with special cases.
+ throw new IllegalStateException("A handler with specialsCount > 0 must have an indexOfSpecial() method."); //$NON-NLS-1$
+ }
+
+ /**
+ * This method handles special cases specific to this handler.
+ * It is called when a special case occurrence
+ * is located by {@link #indexOfSpecial}.
+ *
+ * If a special processing cannot be completed within a current call to
+ * processSpecial
(for instance, a comment has been started
+ * in the current line but its end appears in a following line),
+ * processSpecial
should specify a final state by
+ * putting its value in the first element of the state
+ * parameter.
+ * The meaning of this state is internal to the handler.
+ * On a later call, processSpecial
will be called with that value
+ * for parameter caseNumber
and -1
for parameter
+ * separLocation
and should perform whatever initializations are required
+ * depending on the state.
+ *
+ * A handler handling special cases (with a number of + * special cases greater than zero) must override this method. + *
+ * @param environment the current environment, which may affect the behavior of + * the handler. This parameter may be specified as + *null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @param text is the structured text string before
+ * addition of any directional formatting characters.
+ *
+ * @param charTypes is a parameter received by processSpecial
+ * uniquely to be used as argument for calls to methods which
+ * need it.
+ *
+ * @param offsets is a parameter received by processSpecial
+ * uniquely to be used as argument for calls to methods which
+ * need it.
+ *
+ * @param state is an integer array with at least one element.
+ * If the handler needs to signal the occurrence of a
+ * special case which must be passed to the next call to
+ * leanToFullText
(for instance, a comment or a
+ * literal started but not closed in the current
+ * text
), it must put a value in the first element
+ * of the state
parameter.
+ * This number must be >= 1 and less or equal to the number of special
+ * cases returned by {@link #getSpecialsCount getSpecialsCount}
+ * by this handler.
+ * This number is passed back to the caller
+ * and should be specified as state
argument
+ * in the next call to leanToFullText
together
+ * with the continuation text.
+ * The meaning of this number is internal to the handler.
+ *
+ * @param caseNumber number of the special case to handle.
+ *
+ * @param separLocation the position returned by
+ * {@link #indexOfSpecial indexOfSpecial}. In calls to
+ * {@link ISTextExpert#leanToFullText leanToFullText} and other
+ * methods of {@link ISTextExpert} specifying a non-null
+ * state
parameter, processSpecial
is
+ * called when initializing the processing with the value of
+ * caseNumber
equal to the value returned in the
+ * first element of state
and the value of
+ * separLocation
equal to -1
.
+ *
+ * @return the position after the scope of the special case ends.
+ * For instance, the position after the end of a comment,
+ * the position after the end of a literal.
+ * text
+ * means that there is no further occurrence of this case in the
+ * current structured text.
+ *
+ * @throws IllegalStateException If not overridden, this method throws an
+ * IllegalStateException
. This is appropriate behavior
+ * (and does not need to be overridden) for handlers whose
+ * number of special cases is zero, which means that
+ * processSpecial
should never be called for them.
+ */
+ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) {
+ // This method must be overridden by all subclasses with any special case.
+ throw new IllegalStateException("A handler with specialsCount > 0 must have a processSpecial() method."); //$NON-NLS-1$
+ }
+
+ /**
+ * This method can be called from within {@link #indexOfSpecial} or
+ * {@link #processSpecial} in extensions of STextTypeHandler
+ * to specify that a mark character must be added before the character
+ * at the specified position of the lean text when generating the
+ * full text. The mark character will be LRM for structured text
+ * with a LTR base direction, and RLM for structured text with RTL
+ * base direction. The mark character is not added physically by this
+ * method, but its position is noted and will be used when generating
+ * the full text.
+ *
+ * @param text is the structured text string received as
+ * parameter to indexOfSpecial
or
+ * processSpecial
.
+ *
+ * @param charTypes is a parameter received by indexOfSpecial
+ * or processSpecial
, uniquely to be used as argument
+ * for calls to insertMark
and other methods used
+ * by handlers.
+ *
+ * @param offsets is a parameter received by indexOfSpecial
+ * or processSpecial
, uniquely to be used as argument
+ * for calls to insertMark
and other methods used
+ * by handlers.
+ *
+ * @param offset position of the character in the lean text.
+ * It must be a non-negative number smaller than the length
+ * of the lean text.
+ * For the benefit of efficiency, it is better to insert
+ * multiple marks in ascending order of the offsets.
+ */
+ public static final void insertMark(String text, STextCharTypes charTypes, STextOffsets offsets, int offset) {
+ offsets.insertOffset(charTypes, offset);
+ }
+
+ /**
+ * This method can be called from within {@link #indexOfSpecial} or
+ * {@link #processSpecial} in extensions of STextTypeHandler
to add
+ * a directional mark before a separator if needed for correct display,
+ * depending on the base direction of the text and on the class of the
+ * characters in the lean text preceding and following the separator itself.
+ *
+ * The logic implemented in this method considers the text before
+ * separLocation
and the text following it. If, and only if,
+ * a directional mark is needed to insure that the two parts of text
+ * will be laid out according to the base direction, a mark will be
+ * added when generating the full text.
+ *
indexOfSpecial
or
+ * processSpecial
.
+ *
+ * @param charTypes is a parameter received by indexOfSpecial
+ * or processSpecial
, uniquely to be used as argument
+ * for calls to processSeparator
and other methods used
+ * by handlers.
+ *
+ * @param offsets is a parameter received by indexOfSpecial
+ * or processSpecial
, uniquely to be used as argument
+ * for calls to processSeparator
and other methods used
+ * by handlers.
+ *
+ * @param separLocation offset of the separator in the lean text.
+ * It must be a non-negative number smaller than the length
+ * of the lean text.
+ */
+ public static final void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation) {
+ STextImpl.processSeparator(text, charTypes, offsets, separLocation);
+ }
+
+ /**
+ * Indicate the separators to use for the current handler.
+ * This method is invoked before starting the processing.
+ * + * If no separators are specified, this method returns an empty string. + *
+ * @param environment the current environment, which may affect the behavior of + * the handler. This parameter may be specified as + *null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @return a string grouping one-character separators which separate
+ * the structured text into tokens.
+ */
+ public String getSeparators(STextEnvironment environment) {
+ return separators;
+ }
+
+ /**
+ * Indicate the base text direction appropriate for an instance of structured text.
+ * This method is invoked before starting the processing.
+ *
+ * If not overridden, this method returns DIR_LTR
.
+ *
null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @param text is the structured text string to process.
+ *
+ * @return the base direction of the structured text. This direction
+ * may not be the same depending on the environment and on
+ * whether the structured text contains Arabic or Hebrew
+ * letters.
+ * If not overridden, this method returns DIR_LTR
.
+ *
null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @param text is the structured text string to process.
+ *
+ * @param charTypes is a parameter received uniquely to be used as argument
+ * for calls to getCharType
and other methods used
+ * by handlers.
+ *
+ * @return the base direction of the structured text. This direction
+ * may not be the same depending on the environment and on
+ * whether the structured text contains Arabic or Hebrew
+ * letters.
+ * If not overridden, this method returns zero
.
+ *
null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @return the number of special cases for the associated handler.
+ * Special cases exist for some types of structured text
+ * handlers. They are implemented by overriding methods
+ * {@link STextTypeHandler#indexOfSpecial} and {@link STextTypeHandler#processSpecial}.
+ * Examples of special cases are comments, literals, or
+ * anything which is not identified by a one-character separator.
+ *
+ */
+ public int getSpecialsCount(STextEnvironment environment) {
+ return 0;
+ }
+
+ /**
+ * Checks if there is a need for processing structured text.
+ * This method is invoked before starting the processing. If the
+ * handler returns true
, no directional formatting
+ * characters are added to the lean text and the processing
+ * is shortened.
+ *
+ * If not overridden, this method returns false
.
+ *
null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ *
+ * @param text is the structured text string to process.
+ *
+ * @param charTypes is a parameter received uniquely to be used as argument
+ * for calls to getCharType
and other methods used
+ * by handlers.
+ *
+ * @return a flag indicating if there is no need to process the structured
+ * text to add directional formatting characters.
+ *
+ */
+ public boolean skipProcessing(STextEnvironment environment, String text, STextCharTypes charTypes) {
+ return false;
+ }
+
+}
diff --git src/org/eclipse/equinox/bidi/internal/STextDelims.java src/org/eclipse/equinox/bidi/internal/STextDelims.java
index 110bcc4..ce86629 100644
--- src/org/eclipse/equinox/bidi/internal/STextDelims.java
+++ src/org/eclipse/equinox/bidi/internal/STextDelims.java
@@ -11,11 +11,10 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-
import org.eclipse.equinox.bidi.custom.*;
/**
- * A base processor for structured text composed of text segments separated
+ * A base handler for structured text composed of text segments separated
* by separators where the text segments may include delimited parts within
* which separators are treated like regular characters.
* @@ -23,7 +22,7 @@ *
* @author Matitiahu Allouche */ -public abstract class STextDelims extends STextProcessor { +public abstract class STextDelims extends STextTypeHandler { public STextDelims() { // placeholder @@ -60,7 +59,7 @@ * oftext
if no end delimiter is found.
*/
public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) {
- STextProcessor.processSeparator(text, charTypes, offsets, separLocation);
+ STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
int loc = separLocation + 1;
char delim = getDelimiters().charAt((caseNumber * 2) - 1);
loc = text.indexOf(delim, loc);
diff --git src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
index 37d5217..3f81242 100644
--- src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
+++ src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
@@ -11,11 +11,10 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-
import org.eclipse.equinox.bidi.custom.*;
/**
- * A base processor for structured text composed of text segments separated
+ * A base handler for structured text composed of text segments separated
* by separators where the text segments may include delimited parts within
* which separators are treated like regular characters and the delimiters
* may be escaped.
@@ -51,7 +50,7 @@
* ignoring possibly escaped end delimiters.
*/
public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) {
- STextProcessor.processSeparator(text, charTypes, offsets, separLocation);
+ STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
int location = separLocation + 1;
char delim = getDelimiters().charAt((caseNumber * 2) - 1);
while (true) {
diff --git src/org/eclipse/equinox/bidi/internal/STextExpertImpl.java src/org/eclipse/equinox/bidi/internal/STextExpertImpl.java
deleted file mode 100644
index 985495c..0000000 100644
--- src/org/eclipse/equinox/bidi/internal/STextExpertImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
-
-public class STextExpertImpl implements ISTextExpert {
-
- protected STextProcessor structuredTextDescriptor;
- protected STextEnvironment environment;
-
- // XXX potentially problematic - implementation might write into it?
- private final static int[] initialState = new int[] {0};
-
- public STextExpertImpl(STextProcessor structuredTextDescriptor, STextEnvironment environment) {
- this.structuredTextDescriptor = structuredTextDescriptor;
- this.environment = environment;
- }
-
- public String leanToFullText(String text) {
- return STextImpl.leanToFullText(structuredTextDescriptor, environment, text, initialState);
- }
-
- public int[] leanToFullMap(String text) {
- return STextImpl.leanToFullMap(structuredTextDescriptor, environment, text, initialState);
- }
-
- public int[] leanBidiCharOffsets(String text) {
- return STextImpl.leanBidiCharOffsets(structuredTextDescriptor, environment, text, initialState);
- }
-
- public String fullToLeanText(String text) {
- return STextImpl.fullToLeanText(structuredTextDescriptor, environment, text, initialState);
- }
-
- public int[] fullToLeanMap(String text) {
- return STextImpl.fullToLeanMap(structuredTextDescriptor, environment, text, initialState);
- }
-
- public int[] fullBidiCharOffsets(String text) {
- return STextImpl.fullBidiCharOffsets(structuredTextDescriptor, environment, text, initialState);
- }
-
- public int getCurDirection(String text) {
- return structuredTextDescriptor.getDirection(environment, text);
- }
-
-}
diff --git src/org/eclipse/equinox/bidi/internal/STextExpertMultipassImpl.java src/org/eclipse/equinox/bidi/internal/STextExpertMultipassImpl.java
deleted file mode 100644
index c46ee3c..0000000 100644
--- src/org/eclipse/equinox/bidi/internal/STextExpertMultipassImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * 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;
-
-import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-import org.eclipse.equinox.bidi.advanced.ISTextExpertStateful;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
-
-public class STextExpertMultipassImpl extends STextExpertImpl implements ISTextExpertStateful {
-
- /**
- * Constant to use in the first element of the state
- * argument when calling most methods of this class
- * to indicate that there is no context of previous lines which
- * should be initialized before performing the operation.
- */
- public static final int STATE_INITIAL = 0;
-
- private int[] state = new int[] {STATE_INITIAL};
-
- public STextExpertMultipassImpl(STextProcessor structuredTextDescriptor, STextEnvironment environment) {
- super(structuredTextDescriptor, environment);
- resetState();
- }
-
- public String leanToFullText(String text) {
- return STextImpl.leanToFullText(structuredTextDescriptor, environment, text, state);
- }
-
- public int[] leanToFullMap(String text) {
- return STextImpl.leanToFullMap(structuredTextDescriptor, environment, text, state);
- }
-
- public int[] leanBidiCharOffsets(String text) {
- return STextImpl.leanBidiCharOffsets(structuredTextDescriptor, environment, text, state);
- }
-
- public String fullToLeanText(String text) {
- return STextImpl.fullToLeanText(structuredTextDescriptor, environment, text, state);
- }
-
- public int[] fullToLeanMap(String text) {
- return STextImpl.fullToLeanMap(structuredTextDescriptor, environment, text, state);
- }
-
- public int[] fullBidiCharOffsets(String text) {
- return STextImpl.fullBidiCharOffsets(structuredTextDescriptor, environment, text, state);
- }
-
- public int getCurDirection(String text) {
- return structuredTextDescriptor.getDirection(environment, text);
- }
-
- public void resetState() {
- state[0] = STATE_INITIAL;
- }
-
- public void setState(int newState) {
- state[0] = newState;
- }
-
- public int getState() {
- return state[0];
- }
-
-}
diff --git src/org/eclipse/equinox/bidi/internal/STextImpl.java src/org/eclipse/equinox/bidi/internal/STextImpl.java
index c102319..1137826 100644
--- src/org/eclipse/equinox/bidi/internal/STextImpl.java
+++ src/org/eclipse/equinox/bidi/internal/STextImpl.java
@@ -11,11 +11,10 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.STextDirection;
-import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
+import org.eclipse.equinox.bidi.advanced.*;
import org.eclipse.equinox.bidi.custom.*;
-public class STextImpl {
+public class STextImpl implements ISTextExpertStateful {
static final String EMPTY_STRING = ""; //$NON-NLS-1$
@@ -47,18 +46,67 @@
static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH;
static final int[] EMPTY_INT_ARRAY = new int[0];
static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE);
+ static final int STATE_INITIAL = 0;
+
+ protected STextTypeHandler structuredTextHandler;
+ protected STextEnvironment environment;
+ protected int[] state;
+
+ public STextImpl(STextTypeHandler structuredTextHandler, STextEnvironment environment, int[] state) {
+ this.structuredTextHandler = structuredTextHandler;
+ this.environment = environment;
+ this.state = state;
+ }
+
+ public String leanToFullText(String text) {
+ return STextImpl.leanToFullText(structuredTextHandler, environment, text, state);
+ }
+
+ public int[] leanToFullMap(String text) {
+ return STextImpl.leanToFullMap(structuredTextHandler, environment, text, state);
+ }
+
+ public int[] leanBidiCharOffsets(String text) {
+ return STextImpl.leanBidiCharOffsets(structuredTextHandler, environment, text, state);
+ }
+
+ public String fullToLeanText(String text) {
+ return STextImpl.fullToLeanText(structuredTextHandler, environment, text, state);
+ }
+
+ public int[] fullToLeanMap(String text) {
+ return STextImpl.fullToLeanMap(structuredTextHandler, environment, text, state);
+ }
+
+ public int[] fullBidiCharOffsets(String text) {
+ return STextImpl.fullBidiCharOffsets(structuredTextHandler, environment, text, state);
+ }
+
+ public int getCurDirection(String text) {
+ return structuredTextHandler.getDirection(environment, text);
+ }
+
+ public void resetState() {
+ state[0] = STATE_INITIAL;
+ }
+
+ public void setState(int newState) {
+ state[0] = newState;
+ }
+
+ public static void setState(int[] state, int newState) {
+ if (state != null)
+ state[0] = newState;
+ }
- /**
- * Prevent creation of a STextImpl instance
- */
- private STextImpl() {
- // nothing to do
+ public int getState() {
+ return state[0];
}
- static long computeNextLocation(STextProcessor processor, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) {
- String separators = processor.getSeparators(environment);
+ static long computeNextLocation(STextTypeHandler handler, STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] locations, int curPos) {
+ String separators = handler.getSeparators(environment);
int separCount = separators.length();
- int specialsCount = processor.getSpecialsCount(environment);
+ int specialsCount = handler.getSpecialsCount(environment);
int len = text.length();
int nextLocation = len;
int idxLocation = 0;
@@ -68,7 +116,7 @@
int location = locations[separCount + i];
if (location < curPos) {
offsets.ensureRoom();
- location = processor.indexOfSpecial(environment, text, charTypes, offsets, i + 1, curPos);
+ location = handler.indexOfSpecial(environment, text, charTypes, offsets, i + 1, curPos);
if (location < 0)
location = len;
locations[separCount + i] = location;
@@ -195,12 +243,12 @@
*
* @see ISTextExpert#leanToFullText STextEngine.leanToFullText
*/
- public static String leanToFullText(STextProcessor processor, STextEnvironment environment, String text, int[] state) {
+ public static String leanToFullText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) {
int len = text.length();
if (len == 0)
return text;
- STextCharTypes charTypes = new STextCharTypes(processor, environment, text);
- STextOffsets offsets = leanToFullCommon(processor, environment, text, state, charTypes);
+ STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
+ STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
int prefixLength = offsets.getPrefixLength();
int count = offsets.getCount();
if (count == 0 && prefixLength == 0)
@@ -242,12 +290,12 @@
return new String(fullChars);
}
- public static int[] leanToFullMap(STextProcessor processor, STextEnvironment environment, String text, int[] state) {
+ public static int[] leanToFullMap(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) {
int len = text.length();
if (len == 0)
return EMPTY_INT_ARRAY;
- STextCharTypes charTypes = new STextCharTypes(processor, environment, text);
- STextOffsets offsets = leanToFullCommon(processor, environment, text, state, charTypes);
+ STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
+ STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
int prefixLength = offsets.getPrefixLength();
int[] map = new int[len];
int count = offsets.getCount(); // number of used entries
@@ -262,54 +310,42 @@
return map;
}
- public static int[] leanBidiCharOffsets(STextProcessor processor, STextEnvironment environment, String text, int[] state) {
+ public static int[] leanBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) {
int len = text.length();
if (len == 0)
return EMPTY_INT_ARRAY;
- STextCharTypes charTypes = new STextCharTypes(processor, environment, text);
- STextOffsets offsets = leanToFullCommon(processor, environment, text, state, charTypes);
+ STextCharTypes charTypes = new STextCharTypes(handler, environment, text);
+ STextOffsets offsets = leanToFullCommon(handler, environment, text, state, charTypes);
return offsets.getArray();
}
- /**
- * Constant to use in the first element of the state
- * argument when calling most methods of this class
- * to indicate that there is no context of previous lines which
- * should be initialized before performing the operation.
- */
- public static final int STATE_INITIAL = 0; // TBD move
-
- static STextOffsets leanToFullCommon(STextProcessor processor, STextEnvironment environment, String text, int[] state, STextCharTypes charTypes) {
+ static STextOffsets leanToFullCommon(STextTypeHandler handler, STextEnvironment environment, String text, int[] state, STextCharTypes charTypes) {
if (environment == null)
environment = STextEnvironment.DEFAULT;
- if (state == null) {
- state = new int[1];
- state[0] = STATE_INITIAL;
- }
int len = text.length();
- int direction = processor.getDirection(environment, text, charTypes);
+ int direction = handler.getDirection(environment, text, charTypes);
STextOffsets offsets = new STextOffsets();
- if (!processor.skipProcessing(environment, text, charTypes)) {
+ if (!handler.skipProcessing(environment, text, charTypes)) {
// initialize locations
- int separCount = processor.getSeparators(environment).length();
- int[] locations = new int[separCount + processor.getSpecialsCount(environment)];
+ int separCount = handler.getSeparators(environment).length();
+ int[] locations = new int[separCount + handler.getSpecialsCount(environment)];
for (int i = 0, k = locations.length; i < k; i++) {
locations[i] = -1;
}
// current position
int curPos = 0;
- if (state[0] > STATE_INITIAL) {
+ if (state != null && state[0] > STATE_INITIAL) {
offsets.ensureRoom();
int initState = state[0];
state[0] = STATE_INITIAL;
- curPos = processor.processSpecial(environment, text, charTypes, offsets, state, initState, -1);
+ curPos = handler.processSpecial(environment, text, charTypes, offsets, state, initState, -1);
}
while (true) {
// location of next token to handle
int nextLocation;
// index of next token to handle (if < separCount, this is a separator; otherwise a special case
int idxLocation;
- long res = computeNextLocation(processor, environment, text, charTypes, offsets, locations, curPos);
+ long res = computeNextLocation(handler, environment, text, charTypes, offsets, locations, curPos);
nextLocation = (int) (res & 0x00000000FFFFFFFF); /* low word */
if (nextLocation >= len)
break;
@@ -320,12 +356,12 @@
curPos = nextLocation + 1;
} else {
idxLocation -= (separCount - 1); // because caseNumber starts from 1
- curPos = processor.processSpecial(environment, text, charTypes, offsets, state, idxLocation, nextLocation);
+ curPos = handler.processSpecial(environment, text, charTypes, offsets, state, idxLocation, nextLocation);
}
if (curPos >= len)
break;
} // end while
- } // end if (!processor.skipProcessing())
+ } // end if (!handler.skipProcessing())
int prefixLength;
int orientation = environment.getOrientation();
if (orientation == STextEnvironment.ORIENT_IGNORE)
@@ -343,12 +379,12 @@
return offsets;
}
- public static String fullToLeanText(STextProcessor processor, STextEnvironment environment, String text, int[] state) {
+ public static String fullToLeanText(STextTypeHandler handler, STextEnvironment environment, String text, int[] state) {
if (text.length() == 0)
return text;
if (environment == null)
environment = STextEnvironment.DEFAULT;
- int dir = processor.getDirection(environment, text);
+ int dir = handler.getDirection(environment, text);
char curMark = MARKS[dir];
char curEmbed = EMBEDS[dir];
int i; // used as loop index
@@ -386,7 +422,7 @@
chars[i - cnt] = c;
}
String lean = new String(chars, 0, lenText - cnt);
- String full = leanToFullText(processor, IGNORE_ENVIRONMENT, lean, state);
+ String full = leanToFullText(handler, IGNORE_ENVIRONMENT, lean, state);
if (full.equals(text))
return lean;
@@ -431,13 +467,13 @@
return lean;
}
- public static int[] fullToLeanMap(STextProcessor processor, STextEnvironment environment, String full, int[] state) {
+ public static int[] fullToLeanMap(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) {
int lenFull = full.length();
if (lenFull == 0)
return EMPTY_INT_ARRAY;
- String lean = fullToLeanText(processor, environment, full, state);
+ String lean = fullToLeanText(handler, environment, full, state);
int lenLean = lean.length();
- int dir = processor.getDirection(environment, lean);
+ int dir = handler.getDirection(environment, lean);
char curMark = MARKS[dir];
char curEmbed = EMBEDS[dir];
int[] map = new int[lenFull];
@@ -462,11 +498,11 @@
return map;
}
- public static int[] fullBidiCharOffsets(STextProcessor processor, STextEnvironment environment, String full, int[] state) {
+ public static int[] fullBidiCharOffsets(STextTypeHandler handler, STextEnvironment environment, String full, int[] state) {
int lenFull = full.length();
if (lenFull == 0)
return EMPTY_INT_ARRAY;
- String lean = fullToLeanText(processor, environment, full, state);
+ String lean = fullToLeanText(handler, environment, full, state);
STextOffsets offsets = new STextOffsets();
int lenLean = lean.length();
int idxLean, idxFull;
diff --git src/org/eclipse/equinox/bidi/internal/STextSingle.java src/org/eclipse/equinox/bidi/internal/STextSingle.java
index 42e1be0..3ea4d4a 100644
--- src/org/eclipse/equinox/bidi/internal/STextSingle.java
+++ src/org/eclipse/equinox/bidi/internal/STextSingle.java
@@ -11,26 +11,25 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
-
import org.eclipse.equinox.bidi.custom.*;
/**
- * A base processor for structured text composed of two parts separated by a separator.
+ * A base handler for structured text composed of two parts separated by a separator.
* The first occurrence of the separator delimits the end of the first part
* and the start of the second part. Further occurrences of the separator,
* if any, are treated like regular characters of the second text part.
- * The processor makes sure that the text be presented in the form
+ * The handler makes sure that the text be presented in the form
* (assuming that the equal sign is the separator):
*
* part1=part2 *- * The string returned by {@link STextProcessor#getSeparators getSeparators} - * for this processor should contain exactly one character. + * The string returned by {@link STextTypeHandler#getSeparators getSeparators} + * for this handler should contain exactly one character. * Additional characters will be ignored. * * @author Matitiahu Allouche */ -public class STextSingle extends STextProcessor { +public class STextSingle extends STextTypeHandler { public STextSingle(String separator) { super(separator); @@ -52,12 +51,12 @@ * @return the length of
text
.
*/
public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) {
- STextProcessor.processSeparator(text, charTypes, offsets, separLocation);
+ STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation);
return text.length();
}
/**
- * This method returns 1 as number of special cases handled by this processor.
+ * This method returns 1 as number of special cases handled by this handler.
*
* @return 1.
*/
diff --git src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java
index bbcf564..f97f51e 100644
--- src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java
+++ src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java
@@ -13,7 +13,7 @@
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.*;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
+import org.eclipse.equinox.bidi.custom.STextTypeHandler;
public class STextTypesCollector implements IRegistryEventListener {
@@ -21,7 +21,7 @@
private static final String CE_NAME = "typeDescription"; //$NON-NLS-1$
private static final String ATTR_TYPE = "type"; //$NON-NLS-1$
- private static final String ATTR_PROCESSOR = "class"; //$NON-NLS-1$
+ private static final String ATTR_HANDLER = "class"; //$NON-NLS-1$
private Map types;
private Map factories;
@@ -46,12 +46,12 @@
return result;
}
- public STextProcessor getProcessor(String type) {
+ public STextTypeHandler getHandler(String type) {
if (types == null)
read();
- Object processor = types.get(type);
- if (processor instanceof STextProcessor)
- return (STextProcessor) processor;
+ Object handler = types.get(type);
+ if (handler instanceof STextTypeHandler)
+ return (STextTypeHandler) handler;
return null;
}
@@ -76,14 +76,14 @@
if (CE_NAME != confElements[j].getName())
STextActivator.logError("BiDi types: unexpected element name " + confElements[j].getName(), new IllegalArgumentException()); //$NON-NLS-1$
String type = confElements[j].getAttribute(ATTR_TYPE);
- Object processor;
+ Object handler;
try {
- processor = confElements[j].createExecutableExtension(ATTR_PROCESSOR);
+ handler = confElements[j].createExecutableExtension(ATTR_HANDLER);
} catch (CoreException e) {
- STextActivator.logError("BiDi types: unable to create processor for " + type, e); //$NON-NLS-1$
+ STextActivator.logError("BiDi types: unable to create handler for " + type, e); //$NON-NLS-1$
continue;
}
- types.put(type, processor);
+ types.put(type, handler);
factories.put(type, confElements[j]);
}
}
diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextComma.java src/org/eclipse/equinox/bidi/internal/consumable/STextComma.java
index 418873f..7aab1f4 100644
--- src/org/eclipse/equinox/bidi/internal/consumable/STextComma.java
+++ src/org/eclipse/equinox/bidi/internal/consumable/STextComma.java
@@ -10,15 +10,15 @@
******************************************************************************/
package org.eclipse.equinox.bidi.internal.consumable;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
+import org.eclipse.equinox.bidi.custom.STextTypeHandler;
/**
- * Processor adapted to processing comma-delimited lists, such as:
+ * Handler adapted to processing comma-delimited lists, such as:
* * part1,part2,part3 **/ -public class STextComma extends STextProcessor { +public class STextComma extends STextTypeHandler { public STextComma() { super(","); //$NON-NLS-1$ } diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java index 940f192..2be4a2b 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java @@ -16,7 +16,7 @@ import org.eclipse.equinox.bidi.internal.STextDelimsEsc; /** - * Processor adapted to processing e-mail addresses. + * Handler adapted to processing e-mail addresses. */ public class STextEmail extends STextDelimsEsc { static final byte L = Character.DIRECTIONALITY_LEFT_TO_RIGHT; @@ -59,7 +59,7 @@ } /** - * @return 2 as number of special cases handled by this processor. + * @return 2 as number of special cases handled by this handler. */ public int getSpecialsCount(STextEnvironment environment) { return 2; diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextFile.java src/org/eclipse/equinox/bidi/internal/consumable/STextFile.java index d7185d3..b8f4b10 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextFile.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextFile.java @@ -10,12 +10,12 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.custom.STextProcessor; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** - * Processor adapted to processing directory and file paths. + * Handler adapted to processing directory and file paths. */ -public class STextFile extends STextProcessor { +public class STextFile extends STextTypeHandler { public STextFile() { super(":/\\."); //$NON-NLS-1$ diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java index bb4dff1..5e3d49c 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java @@ -10,13 +10,14 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; -import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.custom.*; import org.eclipse.equinox.bidi.internal.STextActivator; +import org.eclipse.equinox.bidi.internal.STextImpl; /** - *
STextJava
is a processor for structured text
+ * STextJava
is a handler for structured text
* composed of Java statements. Such a structured text may span
* multiple lines.
* @@ -34,7 +35,7 @@ * * @author Matitiahu Allouche */ -public class STextJava extends STextProcessor { +public class STextJava extends STextTypeHandler { private static final byte WS = Character.DIRECTIONALITY_WHITESPACE; static final String lineSep = STextActivator.getInstance().getProperty("line.separator"); //$NON-NLS-1$ @@ -43,7 +44,7 @@ } /** - * @return 4 as the number of special cases handled by this processor. + * @return 4 as the number of special cases handled by this handler. */ public int getSpecialsCount(STextEnvironment environment) { return 4; @@ -85,7 +86,7 @@ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { int location, counter, i; - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); switch (caseNumber) { case 1 : /* space */ separLocation++; @@ -114,12 +115,12 @@ location = separLocation + 2; // skip the opening slash-aster location = text.indexOf("*/", location); //$NON-NLS-1$ if (location < 0) { - state[0] = caseNumber; + STextImpl.setState(state, caseNumber); return text.length(); } // we need to call processSeparator since text may follow the // end of comment immediately without even a space - STextProcessor.processSeparator(text, charTypes, offsets, location); + STextTypeHandler.processSeparator(text, charTypes, offsets, location); return location + 2; case 4 : /* slash-slash comment */ location = text.indexOf(lineSep, separLocation + 2); diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java index 0aa241d..d15af0b 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java @@ -13,13 +13,13 @@ import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.STextCharTypes; -import org.eclipse.equinox.bidi.custom.STextProcessor; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** - * Processor adapted to processing arithmetic expressions with + * Handler adapted to processing arithmetic expressions with * a possible right-to-left base direction. */ -public class STextMath extends STextProcessor { +public class STextMath extends STextTypeHandler { 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; diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextProperty.java src/org/eclipse/equinox/bidi/internal/consumable/STextProperty.java index 994a80e..a99f12f 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextProperty.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextProperty.java @@ -13,7 +13,7 @@ import org.eclipse.equinox.bidi.internal.STextSingle; /** - * Processor adapted to processing property file statements. + * Handler adapted to processing property file statements. * It expects the following string format: *
* name=value diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java index c5d3bb9..4816d4e 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java @@ -11,12 +11,13 @@ 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.advanced.STextEnvironment; -import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.custom.*; +import org.eclipse.equinox.bidi.internal.STextImpl; /** - *STextRegex
is a processor for regular expressions. + *STextRegex
is a handler for regular expressions. * Such expressions may span multiple lines. ** In applications like an editor where parts of the text might be modified @@ -33,7 +34,7 @@ * * @author Matitiahu Allouche */ -public class STextRegex extends STextProcessor { +public class STextRegex extends STextTypeHandler { static final String[] startStrings = {"", /* 0 *//* dummy *///$NON-NLS-1$ "(?#", /* 1 *//* comment (?#...) *///$NON-NLS-1$ "(?<", /* 2 *//* named group (?
*///$NON-NLS-1$ @@ -65,9 +66,9 @@ static final byte EN = Character.DIRECTIONALITY_EUROPEAN_NUMBER; /** - * This method retrieves the number of special cases handled by this processor. + * This method retrieves the number of special cases handled by this handler. * - * @return the number of special cases for this processor. + * @return the number of special cases for this handler. */ public int getSpecialsCount(STextEnvironment environment) { return maxSpecial; @@ -154,13 +155,13 @@ // initial state from previous line location = 0; } else { - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); // skip the opening "(?#" location = separLocation + 3; } location = text.indexOf(')', location); if (location < 0) { - state[0] = caseNumber; + STextImpl.setState(state, caseNumber); return text.length(); } return location + 1; @@ -170,7 +171,7 @@ case 5 : /* conditional named back reference (?( ) */ case 6 : /* conditional named back reference (?('name') */ case 7 : /* named parentheses reference (?&name) */ - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); // no need for calling processSeparator() for the following cases // since the starting string contains a L char case 8 : /* named group (?P */ @@ -194,20 +195,20 @@ // initial state from previous line location = 0; } else { - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); // skip the opening "\Q" location = separLocation + 2; } location = text.indexOf("\\E", location); //$NON-NLS-1$ if (location < 0) { - state[0] = caseNumber; + STextImpl.setState(state, caseNumber); return text.length(); } // set the charType for the "E" to L (Left to Right character) charTypes.setBidiTypeAt(location + 1, L); return location + 2; case 18 : /* R, AL, AN, EN */ - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); return separLocation + 1; } diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java index 9fbe5e4..3b74b43 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java @@ -10,13 +10,14 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; +import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; -import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.custom.*; import org.eclipse.equinox.bidi.internal.STextActivator; +import org.eclipse.equinox.bidi.internal.STextImpl; /** - * STextSql
is a processor for structured text + *STextSql
is a handler for structured text * composed of SQL statements. Such a structured text may span * multiple lines. *@@ -34,7 +35,7 @@ * * @author Matitiahu Allouche */ -public class STextSql extends STextProcessor { +public class STextSql extends STextTypeHandler { private static final byte WS = Character.DIRECTIONALITY_WHITESPACE; static final String lineSep = STextActivator.getInstance().getProperty("line.separator"); //$NON-NLS-1$ @@ -43,7 +44,7 @@ } /** - * @return 5 as the number of special cases handled by this processor. + * @return 5 as the number of special cases handled by this handler. */ public int getSpecialsCount(STextEnvironment environment) { return 5; @@ -89,7 +90,7 @@ public int processSpecial(STextEnvironment environment, String text, STextCharTypes charTypes, STextOffsets offsets, int[] state, int caseNumber, int separLocation) { int location; - STextProcessor.processSeparator(text, charTypes, offsets, separLocation); + STextTypeHandler.processSeparator(text, charTypes, offsets, separLocation); switch (caseNumber) { case 1 : /* space */ separLocation++; @@ -103,7 +104,7 @@ while (true) { location = text.indexOf('\'', location); if (location < 0) { - state[0] = caseNumber; + STextImpl.setState(state, caseNumber); return text.length(); } if ((location + 1) < text.length() && text.charAt(location + 1) == '\'') { @@ -132,12 +133,12 @@ location = separLocation + 2; // skip the opening slash-aster location = text.indexOf("*/", location); //$NON-NLS-1$ if (location < 0) { - state[0] = caseNumber; + STextImpl.setState(state, caseNumber); return text.length(); } // we need to call processSeparator since text may follow the // end of comment immediately without even a space - STextProcessor.processSeparator(text, charTypes, offsets, location); + STextTypeHandler.processSeparator(text, charTypes, offsets, location); return location + 2; case 5 : /* hyphen-hyphen comment */ location = text.indexOf(lineSep, separLocation + 2); diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextSystem.java src/org/eclipse/equinox/bidi/internal/consumable/STextSystem.java index 32b2307..a4241fb 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextSystem.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextSystem.java @@ -13,7 +13,7 @@ import org.eclipse.equinox.bidi.internal.STextSingle; /** - * Processor adapted to processing structured text with the following format: + * Handler adapted to processing structured text with the following format: *
* system(user) *diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextURL.java src/org/eclipse/equinox/bidi/internal/consumable/STextURL.java index 5b2df1a..09794fa 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextURL.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextURL.java @@ -10,12 +10,12 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.custom.STextProcessor; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** - * Processor adapted to processing URLs. + * Handler adapted to processing URLs. */ -public class STextURL extends STextProcessor { +public class STextURL extends STextTypeHandler { public STextURL() { super(":?#/@.[]"); //$NON-NLS-1$ } diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextUnderscore.java src/org/eclipse/equinox/bidi/internal/consumable/STextUnderscore.java index eae11f6..387f39f 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextUnderscore.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextUnderscore.java @@ -10,16 +10,16 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.custom.STextProcessor; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** - * Processor adapted to processing compound names. + * Handler adapted to processing compound names. * This type covers names made of one or more parts, separated by underscores: ** part1_part2_part3 **/ -public class STextUnderscore extends STextProcessor { +public class STextUnderscore extends STextTypeHandler { public STextUnderscore() { super("_"); //$NON-NLS-1$ diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java index 40000ab..637b229 100644 --- src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java +++ src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java @@ -11,11 +11,10 @@ package org.eclipse.equinox.bidi.internal.consumable; import org.eclipse.equinox.bidi.advanced.STextEnvironment; - import org.eclipse.equinox.bidi.internal.STextDelims; /** - * Processor adapted to processing XPath expressions. + * Handler adapted to processing XPath expressions. */ public class STextXPath extends STextDelims { @@ -24,7 +23,7 @@ } /** - * @return 2 as the number of special cases handled by this processor. + * @return 2 as the number of special cases handled by this handler. */ public int getSpecialsCount(STextEnvironment environment) { return 2;