diff --git src/org/eclipse/equinox/bidi/STextProcessor.java src/org/eclipse/equinox/bidi/STextProcessor.java index fcfe7f5..b57a33d 100644 --- src/org/eclipse/equinox/bidi/STextProcessor.java +++ src/org/eclipse/equinox/bidi/STextProcessor.java @@ -14,7 +14,7 @@ import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** - * This class provides a number of convenience functions facilitating the + * Provides a number of convenience functions facilitating the * processing of structured text. * * @noextend This class is not intended to be subclassed by clients. @@ -25,7 +25,8 @@ public final class STextProcessor { /** - * The default set of separators used to segment a string: dot, colon, slash, backslash. + * The default set of separators used to segment a string: dot, + * colon, slash, backslash. */ private static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$ @@ -49,7 +50,7 @@ } /** - * Process the given text and return a string with appropriate + * Processes the given text and returns a string with appropriate * directional formatting characters. This is equivalent to calling * {@link #process(String str, String separators)} with the default * set of separators. @@ -64,20 +65,25 @@ * (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 + * + * @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. + * 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 separators separators by which the string will be segmented - * @return the processed string + * + * @param str the text to process. + * @param separators characters 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)) @@ -118,16 +124,23 @@ // make sure that LRE/PDF are added around the string STextTypeHandler handler = new STextTypeHandler(separators); - ISTextExpert expert = STextExpertFactory.getExpert(handler, env); + ISTextExpert expert = STextExpertFactory.getStatefulExpert(handler, env); return expert.leanToFullText(str); } /** * Processes a string that has a particular semantic meaning to render - * it correctly on bidi locales. + * 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 + * + * @param str the text to process. + * @param textType an identifier for the handler instance appropriate + * for the type of the structured text. + * It may be one of the identifiers defined in + * {@link STextTypeHandlerFactory} or a type handler identifier + * specified in a plug-in. + * * @return the processed string */ public static String processTyped(String str, String textType) { @@ -149,8 +162,10 @@ /** * Removes directional formatting characters in the given string. - * @param str string with directional characters to remove - * @return string without directional formatting characters + * + * @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)) @@ -179,9 +194,16 @@ /** * 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 + * + * @param str string with directional characters to remove. + * + * @param textType an identifier for the handler instance appropriate + * for the type of the structured text. + * It may be one of the identifiers defined in + * {@link STextTypeHandlerFactory} or a type handler identifier + * specified in a plug-in. + * + * @return string without directional formatting characters. */ public static String deprocessTyped(String str, String textType) { if ((str == null) || (str.length() <= 1)) @@ -196,10 +218,10 @@ } /** - * Return the string containing all the default separator characters to be + * Returns a string containing all the default separator characters to be * used to segment a given string. * - * @return string containing all separators + * @return string containing all separators. */ public static String getDefaultSeparators() { return defaultSeparators; diff --git src/org/eclipse/equinox/bidi/STextStringRecord.java src/org/eclipse/equinox/bidi/STextStringRecord.java index 60d48d8..ab22794 100644 --- src/org/eclipse/equinox/bidi/STextStringRecord.java +++ src/org/eclipse/equinox/bidi/STextStringRecord.java @@ -13,7 +13,7 @@ import java.lang.ref.SoftReference; /** - * This class records strings which contain structured text. Several static + * Records strings which contain structured text. Several static * methods in this class allow to record such strings in a pool, and to find if * a given string is member of the pool. *
@@ -73,7 +73,7 @@
}
/**
- * Record a string in the pool. The caller must specify the number
+ * Records a string in the pool. The caller must specify the number
* of segments in the record (at least 1), and the handler, starting
* and ending offsets for the first segment.
*
@@ -82,10 +82,11 @@
* @param segmentCount number of segments allowed in this string.
* This number must be >= 1.
*
- * @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 handler instances, or it may be an instance
- * created by a plug-in or by the application.
+ * @param handlerID identifier for the handler appropriate to handle
+ * the type of structured text present in the first segment.
+ * It may be one of the predefined identifiers in
+ * {@link STextTypeHandlerFactory}, or it may be an identifier
+ * for a type handler created by a plug-in or by the application.
*
* @param start offset in the string of the starting character of the first
* segment. It must be >= 0 and less than the length of the string.
@@ -95,7 +96,7 @@
* not greater than the length of the string.
*
* @return an instance of STextRecordString which represents this record.
- * This instance may be used to specify additional segment with
+ * This instance may be used to specify additional segments with
* {@link #addSegment addSegment}.
*
* @throws IllegalArgumentException if string
is null or
@@ -137,12 +138,13 @@
}
/**
- * Add a second or further segment to a record.
+ * Adds a second or further segment to a record.
*
- * @param handler the handler appropriate to handle the type
- * of structured text present in this segment.
- * 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 handlerID identifier for the handler appropriate to handle
+ * the type of structured text present in the first segment.
+ * It may be one of the predefined identifiers in
+ * {@link STextTypeHandlerFactory}, or it may be an identifier
+ * for a type handler created by a plug-in or by the application.
*
* @param start offset in the string of the starting character of the
* segment. It must be >= 0 and less than the length of the string.
@@ -151,7 +153,7 @@
* greater than the start
argument and not greater
* than the length of the string.
*
- * @throws IllegalArgumentException if handler
is null,
+ * @throws IllegalArgumentException if handlerID
is null,
* or if start
or limit
have invalid
* values.
* @throws IllegalStateException if the current segment exceeds the
@@ -161,7 +163,7 @@
*/
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$
+ throw new IllegalArgumentException("The handlerID 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())
@@ -175,16 +177,16 @@
}
/**
- * Check if a string is recorded and retrieve its record.
+ * Checks if a string is recorded and retrieve its record.
*
* @param string the string to check.
*
* @return null
if the string is not recorded in the pool;
- * otherwise, return the STextStringRecord instance which
- * records this string.
+ * otherwise, return the STextStringRecord
instance
+ * which records this string.
* Once a record has been found, the number of its segments can
* be retrieved using {@link #getSegmentCount getSegmentCount},
- * its handler can
+ * its handler ID can
* be retrieved using {@link #getHandler getHandler},
* its starting offset can
* be retrieved using {@link #getStart getStart},
@@ -223,7 +225,8 @@
}
/**
- * Retrieve the number of segments in a record.
+ * Retrieves the number of segments in a record.
+ *
* @return the number of segments in the current record
*/
public int getSegmentCount() {
@@ -236,21 +239,18 @@
}
/**
- * Retrieve the handler of a given segment.
+ * Retrieves the handler ID of a given segment.
*
* @param segmentNumber number of the segment about which information
* is required. It must be >= 0 and less than the number of
- * segments specified by segmentCount
- * in the call to {@link #addRecord addRecord} which created
- * the STextStringRecord instance.
+ * segments returned by {@link #getSegmentCount}.
*
- * @return the handler to handle the structured text in the segment
+ * @return the handler ID of the handler appropriate to
+ * process the structured text in the segment
* specified by segmentNumber
.
*
* @throws IllegalArgumentException if segmentNumber
* has an invalid value.
- *
- * @see #getSegmentCount
*/
public String getHandler(int segmentNumber) {
checkSegmentNumber(segmentNumber);
@@ -258,21 +258,17 @@
}
/**
- * Retrieve the starting offset of a given segment.
+ * Retrieves the starting offset of a given segment.
*
* @param segmentNumber number of the segment about which information
* is required. It must be >= 0 and less than the number of
- * segments specified by segmentCount
- * in the call to {@link #addRecord addRecord} which created
- * the STextStringRecord instance.
+ * segments returned by {@link #getSegmentCount}.
*
* @return the starting offset within the string of the segment
* specified by segmentNumber
.
*
* @throws IllegalArgumentException if segmentNumber
* has an invalid value.
- *
- * @see #getSegmentCount
*/
public int getStart(int segmentNumber) {
checkSegmentNumber(segmentNumber);
@@ -280,21 +276,17 @@
}
/**
- * Retrieve the ending offset of a given segment.
+ * Retrieves the ending offset of a given segment.
*
* @param segmentNumber number of the segment about which information
* is required. It must be >= 0 and less than the number of
- * segments specified by segmentCount
- * in the call to {@link #addRecord addRecord} which created
- * the STextStringRecord instance.
+ * segments returned by {@link #getSegmentCount}.
*
* @return the offset of the position following the segment
* specified by segmentNumber
.
*
* @throws IllegalArgumentException if segmentNumber
* has an invalid value.
- *
- * @see #getSegmentCount
*/
public int getLimit(int segmentNumber) {
checkSegmentNumber(segmentNumber);
@@ -302,7 +294,7 @@
}
/**
- * Clear the pool. All elements of the pool are erased and any associated
+ * Clears the pool. All elements of the pool are erased and any associated
* memory is freed.
*/
public static synchronized void clear() {
diff --git src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java
index 5889e9b..9a3eba2 100644
--- src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java
+++ src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java
@@ -14,14 +14,14 @@
import org.eclipse.equinox.bidi.internal.STextTypesCollector;
/**
- * This class provides access to registered structured text handlers.
+ * 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:
+ * Structured text handler identifier for property file statements. It expects the following format:
*
* name=value *@@ -29,7 +29,7 @@ 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 + * Structured text handler identifier for compound names. It expects text to be made of one or more * parts separated by underscores: *
* part1_part2_part3 @@ -38,7 +38,7 @@ public static final String UNDERSCORE = "underscore"; //$NON-NLS-1$ /** - * Structured text handler for comma-delimited lists, such as: + * Structured text handler identifier for comma-delimited lists, such as: ** part1,part2,part3 *@@ -46,7 +46,7 @@ public static final String COMMA_DELIMITED = "comma"; //$NON-NLS-1$ /** - * Structured text handler for strings with the following format: + * Structured text handler identifier for strings with the following format: ** system(user) *@@ -54,42 +54,46 @@ public static final String SYSTEM_USER = "system"; //$NON-NLS-1$ /** - * Structured text handler for directory and file paths. + * Structured text handler identifier for directory and file paths. */ public static final String FILE = "file"; //$NON-NLS-1$ /** - * Structured text handler for e-mail addresses. + * Structured text handler identifier for e-mail addresses. */ public static final String EMAIL = "email"; //$NON-NLS-1$ /** - * Structured text handler for URLs. + * Structured text handler identifier for URLs. */ public static final String URL = "url"; //$NON-NLS-1$ /** - * Structured text handler for regular expressions, possibly spanning multiple lines. + * Structured text handler identifier for regular expressions, + * possibly spanning multiple lines. */ public static final String REGEXP = "regex"; //$NON-NLS-1$ /** - * Structured text handler for XPath expressions. + * Structured text handler identifier for XPath expressions. */ public static final String XPATH = "xpath"; //$NON-NLS-1$ /** - * Structured text handler for Java code, possibly spanning multiple lines. + * Structured text handler identifier 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. + * Structured text handler identifier 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. + * Structured text handler identifier for arithmetic expressions, + * possibly with a RTL base direction. */ public static final String RTL_ARITHMETIC = "math"; //$NON-NLS-1$ @@ -101,9 +105,12 @@ } /** - * Obtain a structured text handler of a given type. - * @param id string identifying handler - * @return a handler of the required type, ornull
if the type is unknown + * Obtains a structured text handler of a given type. + * + * @param id the string identifying a structured text handler. + * + * @return a handler of the required type, ornull
+ * if the type is unknown. */ static public STextTypeHandler getHandler(String id) { return STextTypesCollector.getInstance().getHandler(id); diff --git src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java index 535e275..dbb5fb0 100644 --- src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java +++ src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java @@ -13,40 +13,44 @@ import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** + * Advanced API for processing structured text. * For a general introduction to structured text, see - * {@link the package documentation}. + * {@link the org.eclipse.equinox.bidi + * package documentation}. *- * Several common handlers are included in STextEngine. For handlers + * Identifiers for several common handlers are included in + * {@link org.eclipse.equinox.bidi.STextTypeHandlerFactory}. 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
+ * Most of the methods in this interface have atext
* argument which may be just a part of a larger body of text. * When it is the case that the text is submitted in parts with * repeated calls, there may be a need to pass information from * one invocation to the next one. For instance, one invocation * may detect that a comment or a literal has been started but - * has not been completed. In such cases, astate
- * argument must be used. + * has not been completed. In such cases, the state must be managed + * by aISTextExpert
instance obtained with the + * {@link STextExpertFactory#getStatefulExpert getStateful} method. *- * The
state
argument must be an array of integers - * with at least one element. Only the first element is used by - * the methods of this class. + * Thestate
returned after processing a string + * can be retrieved, set and reset using the {@link #getState()}, + * {@link #setState(Object)} and {@link #clearState()} methods. *- * When submitting the initial part of the text, the first element - * of
state
must contain the value {@link #STATE_INITIAL} - * or any value <= 0. + * When submitting the initial part of a text, the state should be + * reset if it is not the first processing call for this + *ISTextExpert
instance. *- * After calling a method with a non-null
state
argument, - * a value is returned in the first element ofstate
. This - * value should be passed unmodified to the method when calling it again - * with the text which is the continuation of the text submitted in the - * last call. + * Values returned by {@link #getState()} are opaque objects whose meaning + * is internal to the relevant structured type handler. These values can only + * be used in {@link #setState(Object) setState} calls to restore a state + * previously obtained after processing a given part of a text before + * processing the next part of the text. *- * When the text submitted to a method is not a continuation and is not - * expected to have a continuation , e.g. it is processed all by itself, - * the
state
argument should be specified asnull
. + * Note that if the user does not modify the state, the state returned by + * a given processing call is automatically passed as initial state to the + * next processing call, provided that the expert is a stateful one. ** Code Samples *
@@ -54,8 +58,9 @@ * (directory and file paths) in order to obtain the full * text corresponding to the given lean text. *
+ * ISTextExpert expert = STextExpertFactory.getExpert(STextTypeHandlerFactory.FILE); * String leanText = "D:\\\u05d0\u05d1\\\u05d2\\\u05d3.ext"; - * String fullText = STextEngine.leanToFullText(STextEngine.PROC_FILE, null, leanText, null); + * String fullText = expert.leanToFullText(leanText); * System.out.println("full text = " + fullText); **@@ -63,12 +68,12 @@ * code in order to obtain the full * text corresponding to the lean text of each line. *
- * Object state = STextState.createState(); + * ISTextExpert expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA); * String leanText = "int i = 3; // first Java statement"; - * String fullText = STextEngine.leanToFullText(STextEngine.PROC_JAVA, null, leanText, state); + * String fullText = expert.leanToFullText(leanText); * System.out.println("full text = " + fullText); * leanText = "i += 4; // next Java statement"; - * fullText = STextEngine.leanToFullText(STextEngine.PROC_JAVA, null, leanText, state); + * fullText = expert.leanToFullText(leanText,); * System.out.println("full text = " + fullText); ** @@ -80,10 +85,10 @@ /** * Constant specifying that the base direction of a structured text is LTR. * The base direction may depend on whether the GUI is - * {@link STextEnvironment#getMirrored mirrored} and may + * {@link STextEnvironment#getMirrored mirrored} and * may be different for Arabic and for Hebrew. * This constant can appear as value returned by the - * {@link #getCurDirection getCurDirection} method. + * {@link #getTextDirection getTextDirection} method. */ public static final int DIR_LTR = 0; @@ -93,30 +98,29 @@ * {@link STextEnvironment#getMirrored mirrored} and may * may be different for Arabic and for Hebrew. * This constant can appear as value returned by the - * {@link #getCurDirection getCurDirection} method. + * {@link #getTextDirection getTextDirection} method. */ public static final int DIR_RTL = 1; + /** + * Obtains the structured type handler associated with this + *ISTextExpert
instance. + * @return the type handler instance. + */ public STextTypeHandler getTypeHandler(); + /** + * Obtains the environment associated with this + *ISTextExpert
instance. + * @return the environment instance. + */ public STextEnvironment getEnvironment(); /** - * Add directional formatting characters to a structured text + * Adds directional formatting characters to a structured text * to ensure correct presentation. * - * @param handler the handler applicable to the text. Ifnull
, - * the method returns unmodified text. - * - * @param environment a bidi environment. Ifnull
, the default environment - * is used. - * * @param text is the structured text string - * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. * * @return the structured text with directional formatting characters added to ensure * correct presentation. @@ -124,29 +128,19 @@ public String leanToFullText(String text); /** - * Given a lean string, compute the positions of each of its + * Given a lean string, computes the positions of each of its * characters within the corresponding full string. - * - * @param handler designates a handler instance. Ifnull
, this - * method returns an identity map. - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. * * @param text is the structured text string. * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. - * - * @return an array which specifies offsets of thetext
characters - * in the full string + * @return an array of integers with one element for each of the + * characters in thetext
argument, equal to the offset + * of the corresponding character in the full string. */ public int[] leanToFullMap(String text); /** - * Given a lean string, compute the offsets of characters + * Given a lean string, computes the offsets of characters * before which directional formatting characters must be added * in order to ensure correct presentation. *@@ -156,17 +150,7 @@ * depending on the {@link STextEnvironment#getOrientation orientation} of the * GUI component used for display are not reflected in this method. *
- * @param handler designates a handler instance - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. - * * @param text is the structured text string - * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. * * @return an array of offsets to the characters in thetext
argument * before which directional marks must be added to ensure correct presentation. @@ -175,20 +159,10 @@ public int[] leanBidiCharOffsets(String text); /** - * Remove directional formatting characters which were added to a + * Removes directional formatting characters which were added to a * structured text string to ensure correct presentation. - * - * @param handler designates a handler instance - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. * * @param text is the structured text string including directional formatting characters. - * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. * * @return the structured text string without directional formatting characters * which might have been added by processing it with {@link #leanToFullText}. @@ -197,31 +171,23 @@ public String fullToLeanText(String text); /** - * Given a full string, compute the positions of each of its + * Given a full string, computes the positions of each of its * characters within the corresponding lean string. - * - * @param handler designates a handler instance - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. * * @param text is the structured text string including directional formatting characters. * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. - * - * @return an array of integers with one element for each of the characters - * in thetext
argument, equal to the offset of the corresponding character - * in the lean string. If there is no corresponding character in the lean string - * (because the specified character is a directional formatting character added when invoking - * {@link #leanToFullText}), the value returned for this character is -1. + * @return an array of integers with one element for each of the + * characters in thetext
argument, equal to the offset + * of the corresponding character in the lean string. + * If there is no corresponding character in the lean string + * (because the specified character is a directional formatting character + * added when invoking {@link #leanToFullText}), + * the value returned for this character is -1. */ public int[] fullToLeanMap(String text); /** - * Given a full string, return the offsets of characters + * Given a full string, returns the offsets of characters * which are directional formatting characters that have been added * in order to ensure correct presentation. *@@ -230,17 +196,7 @@ * or suffixed depending on the {@link STextEnvironment#getOrientation orientation} * of the GUI component used for display. *
- * @param handler designates a handler instance - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. - * * @param text is the structured text string including directional formatting characters - * - * @param state can be used to specify that thetext
argument is - * the continuation of text submitted in a previous call and/or to receive information - * to pass to continuation calls. If all calls to this method are independent from one another, - * this argument should be specified asnull
. * * @return an array of offsets to the characters in thetext
argument which * are directional formatting characters added to ensure correct presentation. The offsets @@ -249,15 +205,16 @@ public int[] fullBidiCharOffsets(String text); /** - * This method adds directional marks to the given text before the characters + * 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
* @see ISTextExpert#leanBidiCharOffsets(String) * @@ -269,8 +226,12 @@ * @param direction the base direction of the structured text. * It must be one of the values {@link #DIR_LTR}, or * {@link #DIR_RTL}. - * @param affix specifies if a prefix and a suffix should be added to - * the result + * @param affixLength specifies the length of prefix and suffix + * which should be added to the result.affix
argument. + * If necessary, leading and trailing directional formatting characters + * (LRE, RLE and PDF) can be added depending on the value of the + *affix
argument. *
+ * 0 means no prefix or suffix
+ * 1 means one LRM or RLM as prefix and no suffix
+ * 2 means 2 characters in both prefix and suffix. + * * @return a string corresponding to the sourcetext
with * directional marks (LRMs or RLMs) added at the specified offsets, * and directional formatting characters (LRE, RLE, PDF) added @@ -283,29 +244,33 @@ * 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 handler designates a handler instance - * - * @param environment specifies an environment whose characteristics may affect - * the handler's behavior. Ifnull
, the default environment is used. - * - * @param text is the structured text string + * @param text is the structured text string. * * @return the base direction of the structured text, {@link #DIR_LTR} or {@link #DIR_RTL} */ public int getTextDirection(String text); - /////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////// // Expert's state handling - can be used only for non-shared experts - - // TBD is there a case where we get a shared expert and setting state is a "must"? - // Javadoc note: shared experts will ignore this + ////////////////////////////////////////////////////////////////////// + /** + * Sets the state for the next text processing call. + * This method does nothing if the expert instance is not a stateful one. + * @param state an object returned by a previous call to {@link #getState}. + */ public void setState(Object state); - // Javadoc note: may return null. Will return null for shared experts + /** + * Gets the state established by the last text processing call. + * This isnull
if the expert instance is not a stateful one, + * or if the last text processing call has nothing to pass to the next call. + * @return the last established state. + */ public Object getState(); /** - * Resets state to initial. + * Resets the state to initial. + * This method does nothing if the expert instance is not a stateful one. */ public void clearState(); } diff --git src/org/eclipse/equinox/bidi/advanced/STextEnvironment.java src/org/eclipse/equinox/bidi/advanced/STextEnvironment.java index 6e21116..474fb00 100644 --- src/org/eclipse/equinox/bidi/advanced/STextEnvironment.java +++ src/org/eclipse/equinox/bidi/advanced/STextEnvironment.java @@ -13,8 +13,8 @@ import org.eclipse.equinox.bidi.internal.STextActivator; /** - * This class describes environment within which structured text strings are - * processed. It includes, for example: + * Describes the environment within which structured text strings are + * processed. It includes: *
true
if bidi processing is needed in this environment
+ * @return true
if bidi processing is needed in this environment.
*/
public boolean isProcessingNeeded() {
if (processingNeeded == null) {
diff --git src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
index 9d66c84..1c567b7 100644
--- src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
+++ src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java
@@ -17,6 +17,23 @@
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
import org.eclipse.equinox.bidi.internal.STextImpl;
+/**
+ * Obtains ISTextExpert instances.
+ * There are two kinds of {@link ISTextExpert} instances (called "experts"):
+ * Only the stateful kind can remember the state established by a call to + * a text processing method and transmit it as initial state in the next call + * to a text processing method. + *
+ * Using a stateful expert is more resource intensive, thus not stateful
+ * experts should be used when feasible.
+ *
+ * @author Matitiahu Allouche
+ *
+ */
final public class STextExpertFactory {
/**
@@ -34,6 +51,13 @@
// prevents instantiation
}
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * a default type handler segmenting the text according to default separators.
+ * This expert instance does not handle states.
+ * @return the ISTextExpert instance.
+ * @see STextProcessor#getDefaultSeparators()
+ */
static public ISTextExpert getExpert() {
if (defaultExpert == null) {
STextTypeHandler handler = new STextTypeHandler(defaultSeparators);
@@ -42,6 +66,18 @@
return defaultExpert;
}
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * the specified type handler.
+ * This expert instance does not handle states.
+ *
+ * @param type the identifier for the required type handler. This identifier
+ * may be one of those listed in {@link STextTypeHandlerFactory}
+ * or it may be have been registered by a plug-in.
+ * @return the ISTextExpert instance.
+ * @throws IllegalArgumentException if type
is not a known type
+ * identifier.
+ */
static public ISTextExpert getExpert(String type) {
ISTextExpert expert;
synchronized (sharedDefaultExperts) {
@@ -49,7 +85,7 @@
if (expert == null) {
STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
- return null;
+ throw new IllegalArgumentException("Invalid type argument"); //$NON-NLS-1$
expert = new STextImpl(handler, STextEnvironment.DEFAULT, false);
sharedDefaultExperts.put(type, expert);
}
@@ -57,6 +93,23 @@
return expert;
}
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * the specified type handler and the specified environment.
+ * This expert instance does not handle states.
+ *
+ * @param type the identifier for the required type handler. This identifier
+ * may be one of those listed in {@link STextTypeHandlerFactory}
+ * or it may be have been registered by a plug-in.
+ * @param environment the current environment, which may affect the behavior of
+ * the expert. This parameter may be specified as
+ * null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ * @return the ISTextExpert instance.
+ * @throws IllegalArgumentException if type
is not a known type
+ * identifier.
+ */
static public ISTextExpert getExpert(String type, STextEnvironment environment) {
ISTextExpert expert;
if (environment == null)
@@ -71,7 +124,7 @@
if (expert == null) {
STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
- return null;
+ throw new IllegalArgumentException("Invalid type argument"); //$NON-NLS-1$
expert = new STextImpl(handler, environment, false);
experts.put(type, expert);
}
@@ -79,20 +132,66 @@
return expert;
}
- static public ISTextExpert getExpert(STextTypeHandler handler, STextEnvironment environment) {
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * the specified type handler and the specified environment.
+ * This expert instance can handle states.
+ *
+ * @param handler the type handler instance. It may have been obtained using
+ * {@link STextTypeHandlerFactory#getHandler(String)} or
+ * by instantiating a type handler.
+ * @param environment the current environment, which may affect the behavior of
+ * the expert. This parameter may be specified as
+ * null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ * @return the ISTextExpert instance.
+ * @throws IllegalArgumentException if type
is not a known type
+ * identifier.
+ */
+ static public ISTextExpert getStatefulExpert(STextTypeHandler handler, STextEnvironment environment) {
if (environment == null)
environment = STextEnvironment.DEFAULT;
return new STextImpl(handler, environment, true);
}
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * the specified type handler.
+ * This expert instance can handle states.
+ *
+ * @param type the identifier for the required type handler. This identifier
+ * may be one of those listed in {@link STextTypeHandlerFactory}
+ * or it may be have been registered by a plug-in.
+ * @return the ISTextExpert instance.
+ * @throws IllegalArgumentException if type
is not a known type
+ * identifier.
+ */
static public ISTextExpert getStatefulExpert(String type) {
return getStatefulExpert(type, STextEnvironment.DEFAULT);
}
+ /**
+ * Obtains a ISTextExpert instance for processing structured text with
+ * the specified type handler and the specified environment.
+ * This expert instance can handle states.
+ *
+ * @param type the identifier for the required type handler. This identifier
+ * may be one of those listed in {@link STextTypeHandlerFactory}
+ * or it may be have been registered by a plug-in.
+ * @param environment the current environment, which may affect the behavior of
+ * the expert. This parameter may be specified as
+ * null
, in which case the
+ * {@link STextEnvironment#DEFAULT DEFAULT}
+ * environment should be assumed.
+ * @return the ISTextExpert instance.
+ * @throws IllegalArgumentException if type
is not a known type
+ * identifier.
+ */
static public ISTextExpert getStatefulExpert(String type, STextEnvironment environment) {
STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
- return null;
+ throw new IllegalArgumentException("Invalid type argument"); //$NON-NLS-1$
if (environment == null)
environment = STextEnvironment.DEFAULT;
return new STextImpl(handler, environment, true);
diff --git src/org/eclipse/equinox/bidi/advanced/package.html src/org/eclipse/equinox/bidi/advanced/package.html
new file mode 0
index 0000000..32abee9 0
--- /dev/null
+++ src/org/eclipse/equinox/bidi/advanced/package.html
@@ -0,0 +1,31 @@
+
+
+
+In particular, the user should use the methods in the +{@link ISTextExpert} class +in the following cases:
+null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
* @param text is the text whose characters are analyzed.
*/
@@ -69,6 +65,18 @@
types = new byte[text.length()];
}
+ /**
+ * Indicates the base text direction appropriate for an instance of
+ * structured text.
+ *
+ * @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.null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
*
* @return the orientation as either
- * {@link STextEnvironment#ORIENT_LTR} or
- * {@link STextEnvironment#ORIENT_RTL}.
+ * {@link STextEnvironment#ORIENT_LTR},
+ * {@link STextEnvironment#ORIENT_RTL},
+ * {@link STextEnvironment#ORIENT_UNKNOWN} or
+ * {@link STextEnvironment#ORIENT_IGNORE}.
*/
- public int resolveOrientation(STextEnvironment envir) {
- int orient = envir.getOrientation();
+ public int resolveOrientation() {
+ int orient = environment.getOrientation();
if ((orient & STextEnvironment.ORIENT_CONTEXTUAL) == 0) { // absolute orientation
return orient;
}
@@ -161,4 +165,5 @@
}
return orient;
}
+
}
diff --git src/org/eclipse/equinox/bidi/custom/STextOffsets.java src/org/eclipse/equinox/bidi/custom/STextOffsets.java
index dd1075d..64e2c0b 100644
--- src/org/eclipse/equinox/bidi/custom/STextOffsets.java
+++ src/org/eclipse/equinox/bidi/custom/STextOffsets.java
@@ -10,6 +10,13 @@
******************************************************************************/
package org.eclipse.equinox.bidi.custom;
+/**
+ * Provides various services related to managing the array of
+ * offsets where directional formatting characters will be inserted.
+ *
+ * @author Matitiahu Allouche
+ *
+ */
public class STextOffsets {
private static final byte L = Character.DIRECTIONALITY_LEFT_TO_RIGHT;
@@ -35,13 +42,17 @@
}
/**
- * Store the prefix length
+ * Stores the prefix length
+ *
+ * @param prefLen value assigned to the prefix length
*/
public void setPrefixLength(int prefLen) {
prefixLength = prefLen;
}
/**
+ * Gets the number of used entries in the offsets array.
+ *
* @return the number of used entries in the offsets array.
*/
public int getCount() {
@@ -49,15 +60,17 @@
}
/**
- * Mark that all entries in the offsets array are unused.
+ * Marks that all entries in the offsets array are unused.
*/
public void clear() {
count = 0;
}
/**
- * Get the value of a specified entry in the offsets array.
- * @param index is the index of the entry of interest.
+ * Gets the value of a specified entry in the offsets array.
+ *
+ * @param index the index of the entry of interest.
+ *
* @return the value of the specified entry.
*/
public int getOffset(int index) {
@@ -65,10 +78,13 @@
}
/**
- * Insert an offset value in the offset array so that the array
+ * Inserts an offset value in the offset array so that the array
* stays in ascending order.
- * @param procData is a group of data accessible to handlers.
- * @param offset is the value to insert.
+ *
+ * @param charTypes an object whose methods can be useful to the
+ * handler.
+ *
+ * @param offset the value to insert.
*/
public void insertOffset(STextCharTypes charTypes, int offset) {
if (count >= offsets.length) {
@@ -114,7 +130,8 @@
}
/**
- * Get all and only the used offset entries.
+ * Gets all and only the used offset entries.
+ *
* @return the current used entries of the offsets array.
*/
public int[] getOffsets() {
@@ -124,4 +141,5 @@
System.arraycopy(offsets, 0, array, 0, count);
return array;
}
+
}
diff --git src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java
index 2a53fa7..64d8668 100644
--- src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java
+++ src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java
@@ -68,37 +68,34 @@
/**
* Creates a new instance of the STextTypeHandler class.
- * @param separators string consisting of characters that split the text into fragments
+ * @param separators string consisting of characters that split the text into fragments.
*/
public STextTypeHandler(String separators) {
this.separators = separators;
}
/**
- * Locate occurrences of special strings within a structured text
- * and return their indexes one after the other in successive calls.
+ * Locates occurrences of special strings within a structured text
+ * and returns their indexes one after the other in successive calls.
* * 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 expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
- * @param text is the structured text string before
+ * @param text 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 charTypes an object whose methods can be useful to the
+ * handler.
*
- * @param offsets is a parameter received by indexOfSpecial
- * uniquely to be used as argument for calls to methods which
- * need it.
+ * @param offsets an object whose methods can be useful to the
+ * handler.
*
* @param caseNumber number of the special case to locate.
* This number varies from 1 to the number of special cases
@@ -132,68 +129,49 @@
}
/**
- * This method handles special cases specific to this handler.
+ * 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.
+ * processSpecial
should specify a final state by calling
+ * {@link ISTextExpert#setState(Object)}.
* 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.
+ *
+ * On a later call, processSpecial
will be called with
+ * -1
for parameter separLocation
. It should then
+ * retrieve the last state by calling {@link ISTextExpert#getState()} and
+ * clear the state by calling {@link ISTextExpert#clearState()}. After that,
+ * it should perform whatever initializations are required
+ * depending on the last 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 expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
- * @param text is the structured text string before
+ * @param text 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 charTypes an object whose methods can be useful to the
+ * handler.
*
- * @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 offsets an object whose methods can be useful 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 #indexOfSpecial indexOfSpecial}. After 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
+ * methods of {@link ISTextExpert} which set a non-null
+ * final state, processSpecial
is
+ * called when initializing the processing with value of
* separLocation
equal to -1
.
*
* @return the position after the scope of the special case ends.
@@ -215,11 +193,11 @@
}
/**
- * 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
+ * Specifies 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
+ * full text. This method can be called from within {@link #indexOfSpecial}
+ * or {@link #processSpecial} in extensions of STextTypeHandler
.
+ * 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
@@ -230,14 +208,10 @@
* 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.
+ * or processSpecial
.
*
* @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.
+ * or processSpecial
.
*
* @param offset position of the character in the lean text.
* It must be a non-negative number smaller than the length
@@ -250,11 +224,12 @@
}
/**
- * 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.
+ * Adds 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. This method
+ * can be called from within {@link #indexOfSpecial} or
+ * {@link #processSpecial} in extensions of STextTypeHandler
.
*
* The logic implemented in this method considers the text before
* separLocation
and the text following it. If, and only if,
@@ -267,14 +242,10 @@
* 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.
+ * or processSpecial
.
*
* @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.
+ * or processSpecial
.
*
* @param separLocation offset of the separator in the lean text.
* It must be a non-negative number smaller than the length
@@ -285,16 +256,15 @@
}
/**
- * Indicate the separators to use for the current handler.
+ * Indicates 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.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
* @return a string grouping one-character separators which separate
* the structured text into tokens.
@@ -304,47 +274,45 @@
}
/**
- * Indicate the base text direction appropriate for an instance of structured text.
- * This method is invoked before starting the processing.
+ * Indicates 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
.
+ * If not overridden, this method returns {@link ISTextExpert#DIR_LTR DIR_LTR}.
*
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
- * @param text is the structured text string to process.
+ * @param text 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
.
+ * If not overridden, this method returns {@link ISTextExpert#DIR_LTR DIR_LTR}.
*
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
* @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.
+ * @param charTypes is a parameter received by indexOfSpecial
+ * or processSpecial
.
*
* @return the base direction of the structured text. This direction
* may not be the same depending on the environment and on
@@ -358,23 +326,23 @@
}
/**
- * Indicate the number of special cases handled by the current handler.
+ * Indicates the number of special cases handled by the current handler.
* This method is invoked before starting the processing.
- * If the number returned is zero, {@link #indexOfSpecial} and
- * {@link #processSpecial} will not be invoked.
+ * If the number returned is zero, {@link #indexOfSpecial indexOfSpecial}
+ * and {@link #processSpecial processSpecial} will not be invoked.
*
* If not overridden, this method returns zero
.
*
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
* @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}.
+ * {@link STextTypeHandler#indexOfSpecial indexOfSpecial} and
+ * {@link STextTypeHandler#processSpecial processSpecial}.
* Examples of special cases are comments, literals, or
* anything which is not identified by a one-character separator.
*
@@ -392,17 +360,15 @@
*
* If not overridden, this method returns false
.
*
null
, in which case the
- * {@link STextEnvironment#DEFAULT DEFAULT}
- * environment should be assumed.
+ * @param expert ISTextExpert instance through which this handler
+ * is invoked. The handler can use ISTextExpert methods to
+ * query items stored in the expert instance, like the current
+ * {@link STextEnvironment environment}.
*
* @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.
+ * @param charTypes is a parameter received by indexOfSpecial
+ * or processSpecial
.
*
* @return a flag indicating if there is no need to process the structured
* text to add directional formatting characters.
diff --git src/org/eclipse/equinox/bidi/custom/package.html src/org/eclipse/equinox/bidi/custom/package.html
index 382a502..e80ae5e 100644
--- src/org/eclipse/equinox/bidi/custom/package.html
+++ src/org/eclipse/equinox/bidi/custom/package.html
@@ -1,25 +1,15 @@
-
-
-
-
-
-
-
-This package provides classes for
-developing structured text processors.
-
-+This package provides classes for +developing structured text type handlers. +
+This package is to be used together with package
+{@link
+org.eclipse.equinox.bidi}.
+
+
diff --git src/org/eclipse/equinox/bidi/internal/STextActivator.java src/org/eclipse/equinox/bidi/internal/STextActivator.java
index effe1a7..f364fe2 100644
--- src/org/eclipse/equinox/bidi/internal/STextActivator.java
+++ src/org/eclipse/equinox/bidi/internal/STextActivator.java
@@ -17,6 +17,9 @@
import org.osgi.framework.*;
import org.osgi.util.tracker.ServiceTracker;
+/**
+ * Provides services related to OSGI bundles.
+ */
public class STextActivator implements BundleActivator {
private ServiceTracker logTracker = null;
diff --git src/org/eclipse/equinox/bidi/internal/STextDelims.java src/org/eclipse/equinox/bidi/internal/STextDelims.java
index d9562bf..d71fcdd 100644
--- src/org/eclipse/equinox/bidi/internal/STextDelims.java
+++ src/org/eclipse/equinox/bidi/internal/STextDelims.java
@@ -33,7 +33,7 @@
}
/**
- * This method locates occurrences of start delimiters.
+ * Locates occurrences of start delimiters.
*
* @return the position starting from offset fromIndex
* in text
of the first occurrence of the
@@ -49,9 +49,8 @@
}
/**
- * This method handles the text between start and end delimiters
- * as a token.
- * It inserts a directional mark if needed at position
+ * Handles the text between start and end delimiters as a token.
+ * This methoed inserts a directional mark if needed at position
* separLocation
which corresponds to a start delimiter,
* and skips until after the matching end delimiter.
*
diff --git src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
index 67b5baf..85f170a 100644
--- src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
+++ src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
@@ -42,9 +42,8 @@
}
/**
- * This method handles the text between start and end delimiters
- * as a token.
- * It inserts a directional mark if needed at position
+ * Handles the text between start and end delimiters as a token.
+ * This method inserts a directional mark if needed at position
* separLocation
which corresponds to a start delimiter,
* and skips until after the matching end delimiter,
* ignoring possibly escaped end delimiters.
diff --git src/org/eclipse/equinox/bidi/internal/STextImpl.java src/org/eclipse/equinox/bidi/internal/STextImpl.java
index de6a2a7..4285ba6 100644
--- src/org/eclipse/equinox/bidi/internal/STextImpl.java
+++ src/org/eclipse/equinox/bidi/internal/STextImpl.java
@@ -14,6 +14,12 @@
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
import org.eclipse.equinox.bidi.custom.*;
+/**
+ * Implementation for ISTextExpert.
+ *
+ * @author Matitiahu Allouche
+ *
+ */
public class STextImpl implements ISTextExpert {
static final String EMPTY_STRING = ""; //$NON-NLS-1$
@@ -304,7 +310,7 @@
if (orientation == STextEnvironment.ORIENT_IGNORE)
prefixLength = 0;
else {
- int resolvedOrientation = charTypes.resolveOrientation(environment);
+ int resolvedOrientation = charTypes.resolveOrientation();
if (orientation != STextEnvironment.ORIENT_UNKNOWN && resolvedOrientation == direction)
prefixLength = 0;
else if ((orientation & STextEnvironment.ORIENT_CONTEXTUAL) != 0)
diff --git src/org/eclipse/equinox/bidi/internal/STextSingle.java src/org/eclipse/equinox/bidi/internal/STextSingle.java
index accaf57..a1bc6ed 100644
--- src/org/eclipse/equinox/bidi/internal/STextSingle.java
+++ src/org/eclipse/equinox/bidi/internal/STextSingle.java
@@ -36,7 +36,7 @@
}
/**
- * This method locates occurrences of the separator.
+ * Locates occurrences of the separator.
*
* @see #getSeparators getSeparators
*/
@@ -45,7 +45,7 @@
}
/**
- * This method inserts a mark before the separator if needed and
+ * Inserts a mark before the separator if needed and
* skips to the end of the source string.
*
* @return the length of text
.
@@ -56,7 +56,7 @@
}
/**
- * This method returns 1 as number of special cases handled by this handler.
+ * 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 f97f51e..4b94cac 100644
--- src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java
+++ src/org/eclipse/equinox/bidi/internal/STextTypesCollector.java
@@ -15,6 +15,9 @@
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
+/**
+ * Provides services related to registered structured text handlers.
+ */
public class STextTypesCollector implements IRegistryEventListener {
private static final String EXT_POINT = "org.eclipse.equinox.bidi.bidiTypes"; //$NON-NLS-1$
diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
index 7efdfd1..e987291 100644
--- src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
+++ src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
@@ -15,21 +15,20 @@
import org.eclipse.equinox.bidi.internal.STextActivator;
/**
- * STextJava
is a handler for structured text
- * composed of Java statements. Such a structured text may span
- * multiple lines.
+ * Handler for structured text composed of Java statements.
+ * Such a structured text may span multiple lines.
*
* In applications like an editor where parts of the text might be modified
* while other parts are not, the user may want to call
* {@link ISTextExpert#leanToFullText}
* separately on each line and save the initial state of each line (this is
* the final state of the previous line which can be retrieved using
- * the value returned in the first element of the state
argument).
+ * {@link ISTextExpert#getState()}).
* If both the content
* of a line and its initial state have not changed, the user can be sure that
* the last full text computed for this line has not changed either.
*
- * @see ISTextExpert#leanToFullText explanation of state in leanToFullText
+ * @see ISTextExpert explanation of state
*
* @author Matitiahu Allouche
*/
@@ -50,7 +49,7 @@
}
/**
- * This method looks for occurrences of 4 special strings:
+ * Locates occurrences of 4 special strings:
*
STextRegex
is a handler for regular expressions.
+ * Handler for regular expressions.
* Such expressions may span multiple lines.
*
* In applications like an editor where parts of the text might be modified
@@ -23,12 +23,12 @@
* {@link ISTextExpert#leanToFullText}
* separately on each line and save the initial state of each line (this is
* the final state of the previous line which can be retrieved using
- * the value returned in the first element of the state
argument).
+ * {@link ISTextExpert#getState()}.
* If both the content
* of a line and its initial state have not changed, the user can be sure that
* the last full text computed for this line has not changed either.
*
- * @see ISTextExpert#leanToFullText explanation of state in leanToFullText
+ * @see ISTextExpert explanation of state
*
* @author Matitiahu Allouche
*/
@@ -66,7 +66,7 @@
private static final Integer STATE_QUOTED_SEQUENCE = new Integer(17);
/**
- * This method retrieves the number of special cases handled by this handler.
+ * Retrieves the number of special cases handled by this handler.
*
* @return the number of special cases for this handler.
*/
@@ -75,7 +75,7 @@
}
/**
- * This method locates occurrences of the syntactic strings and of
+ * Locates occurrences of the syntactic strings and of
* R, AL, EN, AN characters.
*/
public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
@@ -144,7 +144,7 @@
}
/**
- * This method process the special cases.
+ * Processes the special cases.
*/
public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
int location;
diff --git src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
index 0ea92a7..4ab4276 100644
--- src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
+++ src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
@@ -15,21 +15,20 @@
import org.eclipse.equinox.bidi.internal.STextActivator;
/**
- * STextSql
is a handler for structured text
- * composed of SQL statements. Such a structured text may span
- * multiple lines.
+ * Handler for structured text composed of SQL statements.
+ * Such a structured text may span multiple lines.
*
* In applications like an editor where parts of the text might be modified
* while other parts are not, the user may want to call
* {@link ISTextExpert#leanToFullText}
* separately on each line and save the initial state of each line (this is
- * the final state of the previous line which can be retrieved from the
- * value returned in the first element of the state
argument).
+ * the final state of the previous line which can be retrieved by calling
+ * {@link ISTextExpert#getState()}.
* If both the content
* of a line and its initial state have not changed, the user can be sure that
* the last full text computed for this line has not changed either.
*
- * @see ISTextExpert#leanToFullText explanation of state in leanToFullText
+ * @see ISTextExpert explanation of state
*
* @author Matitiahu Allouche
*/
@@ -51,7 +50,7 @@
}
/**
- * This method looks for occurrences of 5 special strings:
+ * Locates occurrences of 5 special strings:
*
-There are various types of structured text. Each type should -be handled by a specific processor. A number of standard -processors are supplied in the associated package -{@link -org.eclipse.equinox.bidi.internal.consumable}. - -
-Bidirectional text offers interesting challenges to presentation systems. -For plain text, the Unicode Bidirectional Algorithm -(UBA) -generally specifies satisfactorily how to reorder bidirectional text for -display. This algorithm is implemented in Java's presentation system. -
-However, all bidirectional text is not necessarily plain text. There -are also instances of text structured to follow a given syntax, which -should be reflected in the display order. The general algorithm, which -has no awareness of these special cases, often gives incorrect results -when displaying such structured text. -
-The general idea in handling structured text is to add directional -formatting characters at proper locations in the text to supplement the -standard algorithm, so that the final result is correctly displayed -using the UBA. -
-A class which handles structured text is thus essentially a -transformation engine which receives text without directional formatting -characters as input and produces as output the same text with added -directional formatting characters, hopefully in the minimum quantity -which is sufficient to ensure correct display, considering the type of -structured text involved. -
-In this package, text without directional formatting characters is -called lean text while the text with added directional -formatting characters is called full text. -
-The class {@link -STextEngine} -is the main tool for processing structured text. It facilitates -handling several types of structured text, each type being handled -by a specific -{@link processor} :
--For each of these types, a static instance is defined in STextEngine. -These pre-defined instances can be used as argument in the methods of -STextEngine. -
-Other classes in this package may be used to -complement and facilitate the action of -{@link STextEngine}: -
-{@link STextEngine} and the -other classes mentioned above are intended for users who -need to process structured text for which there already exist -processors. -
-Developers who want to develop new processors to support types of structured text -not currently supported can use the following components of the -package {@link -org.eclipse.equinox.bidi.custom}: -
-There are two other packages associated with the current one: -
-However, users wishing to process the currently supported types of -structured text typically don't need to interact with these -two packages. - -
- -
- -
The proposed solution is making extensive usage of LRM, RLM, LRE, RLE -and PDF directional controls which are invisible but affect the way bidi -text is displayed. The following related key points merit special -attention:
- -+There are various types of structured text. Each type should +be handled by a specific type handler. A number of standard +type handlers are supplied in the associated package + +org.eclipse.equinox.bidi.internal.consumable. + +
+Bidirectional text offers interesting challenges to presentation systems. +For plain text, the Unicode Bidirectional Algorithm +(UBA) +generally specifies satisfactorily how to reorder bidirectional text for +display. This algorithm is implemented in Java's presentation system. +
+However, all bidirectional text is not necessarily plain text. There +are also instances of text structured to follow a given syntax, which +should be reflected in the display order. The general algorithm, which +has no awareness of these special cases, often gives incorrect results +when displaying such structured text. +
+The general idea in handling structured text in this package is to add +directional formatting characters at proper locations in the text to +supplement the standard algorithm, so that the final result is correctly +displayed using the UBA. +
+A class which handles structured text is thus essentially a +transformation engine which receives text without directional formatting +characters as input and produces as output the same text with added +directional formatting characters, hopefully in the minimum quantity +which is sufficient to ensure correct display, considering the type of +structured text involved. +
+In this package, text without directional formatting characters is +called lean text while the text with added directional +formatting characters is called full text. +
+The class {@link +STextProcessor} +is the main tool for processing structured text. It facilitates +handling several types of structured text, each type being handled +by a specific +{@link +type handler} :
++For each of these types, an identifier is defined in +{@link +STextTypeHandlerFactory} :
+These identifiers can be used as argument in some methods of +STextProcessor to specify the type of handler to apply. ++Another class in this package may be used to +complement the action of +{@link STextProcessor}: +
+The classes included in this package are intended for users who +need to process structured text in the most straightforward +manner, when the following conditions are satisfied: +
+When their needs go beyond the conditions above, +users can use classes in the +{@link +org.eclipse.equinox.bidi.advanced} package: +
STextExpert
instance for the user.
++Developers who want to develop new handlers to support types of +structured text not currently supported can use the following components +of the package {@link +org.eclipse.equinox.bidi.custom}: +
+There are two other packages associated with the current one: +
+However, users wishing to process the currently supported types of +structured text typically don't need to interact with these +two packages. + +
+ +
+ +
The proposed solution is making extensive usage of LRM, RLM, LRE, RLE +and PDF directional controls which are invisible but affect the way bidi +text is displayed. The following related key points merit special +attention:
+ +