aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOleg Besedin2011-07-26 14:27:46 (EDT)
committerOleg Besedin2011-07-27 15:30:15 (EDT)
commitb7cf1b1837caf9691753413b9e42103d312d4347 (patch)
treeb2d732490d3e2c0f1eeb935f71b2ecefd750f3a2
parent2883815e408713e8fb8200d84294a2b8789943e7 (diff)
downloadrt.equinox.bundles-b7cf1b1837caf9691753413b9e42103d312d4347.zip
rt.equinox.bundles-b7cf1b1837caf9691753413b9e42103d312d4347.tar.gz
rt.equinox.bundles-b7cf1b1837caf9691753413b9e42103d312d4347.tar.bz2
Bug 183164 - API direction cache
-rw-r--r--bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java29
-rw-r--r--bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java2
-rw-r--r--bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java13
-rw-r--r--bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextTest.java6
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextEngine.java4
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorFactory.java4
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorMultipass.java47
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextDirections.java133
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextProcessor.java69
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java5
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java3
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java149
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java7
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java8
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java9
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java5
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java19
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java9
-rw-r--r--bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java3
19 files changed, 294 insertions, 230 deletions
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java
index ebfabd9..933f761 100644
--- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java
+++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextMethodsTest.java
@@ -12,6 +12,7 @@
package org.eclipse.equinox.bidi.internal.tests;
import org.eclipse.equinox.bidi.*;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -34,20 +35,20 @@ public class STextMethodsTest extends STextTestBase {
class MyComma extends STextProcessor {
- public String getSeparators(STextEnvironment environment, String text, byte[] dirProps) {
+ public String getSeparators(STextEnvironment environment, String text, STextDirections dirProps) {
return ","; //$NON-NLS-1$
}
- public boolean skipProcessing(STextEnvironment environment, String text, byte[] dirProps) {
- byte dirProp = getDirProp(text, dirProps, 0);
+ public boolean skipProcessing(STextEnvironment environment, String text, STextDirections dirProps) {
+ byte dirProp = dirProps.getOrientationAt(0);
if (dirProp == AL)
return true;
return false;
}
- public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getDirection(STextEnvironment environment, String text, STextDirections dirProps) {
for (int i = 0; i < text.length(); i++) {
- byte dirProp = getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == AL)
return dirArabic;
}
@@ -185,15 +186,19 @@ public class STextMethodsTest extends STextTestBase {
dirArabic = RTL;
dirHebrew = LTR;
msg = "TestDirection #1";
- dirA = processor.getDirection(null, toUT16("###"), null);
- dirH = processor.getDirection(null, toUT16("ABC"), null);
+ String text = toUT16("###");
+ dirA = processor.getDirection(null, text, new STextDirections(text));
+ text = toUT16("ABC");
+ dirH = processor.getDirection(null, toUT16("ABC"), new STextDirections(text));
assertTrue(msg, dirA == RTL && dirH == LTR);
dirArabic = RTL;
dirHebrew = RTL;
msg = "TestDirection #2";
- dirA = processor.getDirection(null, toUT16("###"), null);
- dirH = processor.getDirection(null, toUT16("ABC"), null);
+ text = toUT16("###");
+ dirA = processor.getDirection(null, text, new STextDirections(text));
+ text = toUT16("ABC");
+ dirH = processor.getDirection(null, text, new STextDirections(text));
assertTrue(msg, dirA == RTL && dirH == RTL);
dirArabic = dirHebrew = LTR;
@@ -212,8 +217,10 @@ public class STextMethodsTest extends STextTestBase {
dirArabic = RTL;
msg = "TestDirection #10.5";
- dirA = processor.getDirection(null, toUT16("###"), null);
- dirH = processor.getDirection(null, toUT16("ABC"), null);
+ text = toUT16("###");
+ dirA = processor.getDirection(null, text, new STextDirections(text));
+ text = toUT16("ABC");
+ dirH = processor.getDirection(null, text, new STextDirections(text));
assertTrue(msg, dirA == RTL && dirH == LTR);
STextEnvironment environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR);
data = "ABC,#DEF,HOST,com";
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java
index 00fedc9..09fb238 100644
--- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java
+++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextNullProcessorTest.java
@@ -14,7 +14,7 @@ package org.eclipse.equinox.bidi.internal.tests;
import org.eclipse.equinox.bidi.STextEngine;
/**
- * Tests RTL arithmetic
+ * Tests null processor
*/
public class STextNullProcessorTest extends STextTestBase {
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java
index 88d89b3..4e64ee8 100644
--- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java
+++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextSomeMoreTest.java
@@ -13,6 +13,7 @@ package org.eclipse.equinox.bidi.internal.tests;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -26,15 +27,15 @@ public class STextSomeMoreTest extends STextTestBase {
class Processor1 extends STextProcessor {
- public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment env, String text, STextDirections dirProps) {
return 1;
}
- public int indexOfSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment env, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
return fromIndex;
}
- public int processSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment env, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
int len = text.length();
for (int i = len - 1; i >= 0; i--) {
STextProcessor.insertMark(text, dirProps, offsets, i);
@@ -46,7 +47,7 @@ public class STextSomeMoreTest extends STextTestBase {
class Processor2 extends STextProcessor {
- public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment env, String text, STextDirections dirProps) {
return 1;
}
@@ -54,11 +55,11 @@ public class STextSomeMoreTest extends STextTestBase {
class Processor3 extends STextProcessor {
- public int getSpecialsCount(STextEnvironment env, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment env, String text, STextDirections dirProps) {
return 1;
}
- public int indexOfSpecial(STextEnvironment env, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment env, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
return fromIndex;
}
}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextTest.java
index f70828f..6d8149a 100644
--- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextTest.java
+++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextTest.java
@@ -10,13 +10,11 @@
******************************************************************************/
package org.eclipse.equinox.bidi.internal.tests;
-import org.eclipse.equinox.bidi.STextEnvironment;
import org.eclipse.equinox.bidi.custom.STextProcessor;
public class STextTest extends STextProcessor {
- public String getSeparators(STextEnvironment env, String text, byte[] dirProps) {
- return "-=.:";
+ public STextTest() {
+ super("-=.:");
}
-
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextEngine.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextEngine.java
index aa90a66..df2201a 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextEngine.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextEngine.java
@@ -10,6 +10,7 @@
******************************************************************************/
package org.eclipse.equinox.bidi;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
import org.eclipse.equinox.bidi.internal.STextImpl;
@@ -295,6 +296,7 @@ public class STextEngine {
return STextImpl.fullBidiCharOffsets(processor, environment, text, state);
}
+ // TBD why is this method here and not just in the processor? Is it interesting in general?
/**
* Get the base direction of a structured text. This base direction may depend on
* whether the text contains Arabic or Hebrew words. If the text contains both,
@@ -312,7 +314,7 @@ public class STextEngine {
public static int getCurDirection(STextProcessor processor, STextEnvironment environment, String text) {
if (processor == null)
return DIR_LTR;
- return STextImpl.getCurDirection(processor, environment, text, null);
+ return processor.getDirection(environment, text, new STextDirections(text));
}
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorFactory.java
index d15f338..5338c38 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorFactory.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorFactory.java
@@ -116,4 +116,8 @@ final public class STextProcessorFactory {
static public STextProcessor getProcessor(String id) {
return STextTypesCollector.getInstance().getProcessor(id);
}
+
+ static public STextProcessor getMultiProcessor(String id) {
+ return new STextProcessorMultipass();
+ }
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorMultipass.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorMultipass.java
new file mode 100644
index 0000000..63d8877
--- /dev/null
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessorMultipass.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 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.STextImpl;
+
+public class STextProcessorMultipass extends STextProcessor {
+
+ private int[] state = new int[] {0};
+
+ public STextProcessorMultipass() {
+
+ }
+
+ public String leanToFullText(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.leanToFullText(processor, environment, text, state);
+ }
+
+ public int[] leanToFullMap(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.leanToFullMap(processor, environment, text, state);
+ }
+
+ public int[] leanBidiCharOffsets(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.leanBidiCharOffsets(processor, environment, text, state);
+ }
+
+ public String fullToLeanText(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.fullToLeanText(processor, environment, text, state);
+ }
+
+ public int[] fullToLeanMap(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.fullToLeanMap(processor, environment, text, state);
+ }
+
+ public int[] fullBidiCharOffsets(STextProcessor processor, STextEnvironment environment, String text) {
+ return STextImpl.fullBidiCharOffsets(processor, environment, text, state);
+ }
+}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextDirections.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextDirections.java
new file mode 100644
index 0000000..2d1e5ef
--- /dev/null
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextDirections.java
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * Copyright (c) 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.STextEnvironment;
+
+/**
+ * The class determines bidirectional types of characters in a string.
+ */
+public class STextDirections {
+
+ // In the following lines, B, L, R and AL represent bidi categories
+ // as defined in the Unicode Bidirectional Algorithm
+ // ( http://www.unicode.org/reports/tr9/ ).
+ // B represents the category Block Separator.
+ // L represents the category Left to Right character.
+ // R represents the category Right to Left character.
+ // AL represents the category Arabic Letter.
+ // AN represents the category Arabic Number.
+ // EN represents the category European Number.
+ static final byte B = Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR;
+ 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;
+ static final byte AN = Character.DIRECTIONALITY_ARABIC_NUMBER;
+ static final byte EN = Character.DIRECTIONALITY_EUROPEAN_NUMBER;
+
+ // TBD consider moving L, R, AL, AN, EN, B into this class from STextImpl
+ // TBD add methods:
+ // isRTL (dirProp == R || dirProp == AL)
+ // isLTR (dirProp == L || dirProp == EN)
+ // isStrong (isRTL() || isLTR() || dirProp == AN) <= excludes unknown, B, WS
+
+ final protected String text;
+
+ // 1 byte for each char in text
+ private byte[] dirProps;
+
+ // current orientation
+ private byte baseOrientation = 0; // "0" means "unknown"
+
+ public STextDirections(String text) {
+ this.text = text;
+ dirProps = new byte[text.length()];
+ }
+
+ public void setBaseOrientation(byte orientation) {
+ baseOrientation = orientation;
+ }
+
+ public byte getBaseOrientation() {
+ return baseOrientation;
+ }
+
+ private byte getCachedDirectionAt(int index) {
+ return (byte) (dirProps[index] - 1);
+ }
+
+ private boolean hasCachedDirectionAt(int i) {
+ return (dirProps[i] != 0); // "0" means "unknown"
+ }
+
+ /**
+ * @param dirProp bidirectional class of the character. It must be
+ * one of the values which can be returned by
+ * <code>java.lang.Character.getDirectionality</code>.
+ */
+ public void setOrientationAt(int i, byte dirProp) {
+ dirProps[i] = (byte) (dirProp + 1);
+ }
+
+ public int getBaseOrientation(STextEnvironment environment) {
+ int result;
+ int orient = environment.getOrientation();
+ if ((orient & STextEnvironment.ORIENT_CONTEXTUAL_LTR) == 0) { // absolute orientation
+ result = orient;
+ } else { // contextual orientation:
+ result = orient & 1; // initiate to the default orientation minus contextual bit
+ int len = text.length();
+ byte dirProp;
+ for (int i = 0; i < len; i++) {
+ if (!hasCachedDirectionAt(i)) {
+ dirProp = Character.getDirectionality(text.charAt(i));
+ if (dirProp == B) // B char resolves to L or R depending on orientation
+ continue;
+ setOrientationAt(i, dirProp);
+ } else {
+ dirProp = getCachedDirectionAt(i);
+ }
+ if (dirProp == L) { // TBD || == EN ?
+ result = STextEnvironment.ORIENT_LTR;
+ break;
+ }
+ if (dirProp == R || dirProp == AL) {
+ result = STextEnvironment.ORIENT_RTL;
+ break;
+ }
+ }
+ if (result == -1) // return the default orientation minus contextual bit
+ result = orient & 1;
+ }
+ baseOrientation = (byte) result;
+ return result;
+ }
+
+ /**
+ * Returns directionality of the character in the original string at
+ * the specified index.
+ * @param index position of the character in the <i>lean</i> text
+ * @return the bidirectional class of the character. It is one of the
+ * values which can be returned by {@link Character#getDirectionality(char)}
+ */
+ public byte getOrientationAt(int index) {
+ if (hasCachedDirectionAt(index))
+ return getCachedDirectionAt(index);
+ byte dirProp = Character.getDirectionality(text.charAt(index));
+ if (dirProp == B) {
+ byte orient = getBaseOrientation();
+ dirProp = (orient == STextEnvironment.ORIENT_RTL) ? R : L;
+ }
+ setOrientationAt(index, dirProp);
+ return dirProp;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextProcessor.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextProcessor.java
index 8889373..481f1a3 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextProcessor.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextProcessor.java
@@ -132,7 +132,7 @@ public class STextProcessor {
* number of special cases is zero, which means that
* <code>indexOfSpecial</code> should never be called for them.
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] 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$
}
@@ -216,66 +216,13 @@ public class STextProcessor {
* number of special cases is zero, which means that
* <code>processSpecial</code> should never be called for them.
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] 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 <code>STextProcessor</code> to retrieve
- * the bidirectional class of characters in the <i>lean</i> text.
- *
- * @param text is the structured text string received as
- * parameter to <code>indexOfSpecial</code> or
- * <code>processSpecial</code>.
- *
- * @param dirProps is a parameter received by <code>indexOfSpecial</code>
- * or <code>processSpecial</code>, uniquely to be used as argument
- * for calls to <code>getDirProp</code> and other methods used
- * by processors.
- *
- * @param index position of the character in the <i>lean</i> text.
- * It must be a non-negative number smaller than the length
- * of the <i>lean</i> text.
- *
- * @return the bidirectional class of the character. It is one of the
- * values which can be returned by
- * <code>java.lang.Character.getDirectionality</code>.
- * However, it is recommended to use <code>getDirProp</code>
- * rather than <code>java.lang.Character.getDirectionality</code>
- * since <code>getDirProp</code> manages a cache of character
- * properties and so can be more efficient than calling the
- * java.lang.Character method.
- */
- public static final byte getDirProp(String text, byte[] dirProps, int index) {
- return STextImpl.getDirProp(text, dirProps, index);
- }
-
- /**
- * This method can be called from within {@link #indexOfSpecial} or
- * {@link #processSpecial} in extensions of <code>STextProcessor</code> to set or
- * override the bidirectional class of characters in the <i>lean</i> text.
- *
- * @param dirProps is a parameter received by <code>indexOfSpecial</code>
- * or <code>processSpecial</code>, uniquely to be used as argument
- * for calls to <code>setDirProp</code> and other methods used
- * by processors.
- *
- * @param index position of the character in the <i>lean</i> text.
- * It must be a non-negative number smaller than the length
- * of the <i>lean</i> text.
- *
- * @param dirProp bidirectional class of the character. It must be
- * one of the values which can be returned by
- * <code>java.lang.Character.getDirectionality</code>.
- */
- public static final void setDirProp(byte[] dirProps, int index, byte dirProp) {
- STextImpl.setDirProp(dirProps, index, dirProp);
- }
-
- /**
- * This method can be called from within {@link #indexOfSpecial} or
* {@link #processSpecial} in extensions of <code>STextProcessor</code>
* to specify that a mark character must be added before the character
* at the specified position of the <i>lean</i> text when generating the
@@ -305,7 +252,7 @@ public class STextProcessor {
* 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, byte[] dirProps, int[] offsets, int offset) {
+ public static final void insertMark(String text, STextDirections dirProps, int[] offsets, int offset) {
STextImpl.insertMark(text, dirProps, offsets, offset);
}
@@ -340,7 +287,7 @@ public class STextProcessor {
* It must be a non-negative number smaller than the length
* of the <i>lean</i> text.
*/
- public static final void processSeparator(String text, byte[] dirProps, int[] offsets, int separLocation) {
+ public static final void processSeparator(String text, STextDirections dirProps, int[] offsets, int separLocation) {
STextImpl.processSeparator(text, dirProps, offsets, separLocation);
}
@@ -365,7 +312,7 @@ public class STextProcessor {
* @return a string grouping one-character separators which separate
* the structured text into tokens.
*/
- public String getSeparators(STextEnvironment environment, String text, byte[] dirProps) {
+ public String getSeparators(STextEnvironment environment, String text, STextDirections dirProps) {
return separators;
}
@@ -394,7 +341,7 @@ public class STextProcessor {
* The value returned is either
* {@link STextEngine#DIR_LTR DIR_LTR} or {@link STextEngine#DIR_RTL DIR_RTL}.
*/
- public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getDirection(STextEnvironment environment, String text, STextDirections dirProps) {
return STextEngine.DIR_LTR;
}
@@ -426,7 +373,7 @@ public class STextProcessor {
* anything which is not identified by a one-character separator.
*
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 0;
}
@@ -455,7 +402,7 @@ public class STextProcessor {
* text to add directional formatting characters.
*
*/
- public boolean skipProcessing(STextEnvironment environment, String text, byte[] dirProps) {
+ public boolean skipProcessing(STextEnvironment environment, String text, STextDirections dirProps) {
return false;
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java
index f6061fd..dd0bc3a 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelims.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -43,7 +44,7 @@ public abstract class STextDelims extends STextProcessor {
*
* @see #getDelimiters
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
char delim = getDelimiters().charAt((caseNumber - 1) * 2);
return text.indexOf(delim, fromIndex);
}
@@ -58,7 +59,7 @@ public abstract class STextDelims extends STextProcessor {
* @return the position after the matching end delimiter, or the length
* of <code>text</code> if no end delimiter is found.
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
int loc = separLocation + 1;
char delim = getDelimiters().charAt((caseNumber * 2) - 1);
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
index 564cead..25438e6 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextDelimsEsc.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -49,7 +50,7 @@ public abstract class STextDelimsEsc extends STextDelims {
* and skips until after the matching end delimiter,
* ignoring possibly escaped end delimiters.
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
int location = separLocation + 1;
char delim = getDelimiters().charAt((caseNumber * 2) - 1);
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java
index 77d365a..f7d7c35 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextImpl.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -25,12 +26,23 @@ import org.eclipse.equinox.bidi.custom.STextProcessor;
public class STextImpl {
static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+ // In the following lines, B, L, R and AL represent bidi categories
+ // as defined in the Unicode Bidirectional Algorithm
+ // ( http://www.unicode.org/reports/tr9/ ).
+ // B represents the category Block Separator.
+ // L represents the category Left to Right character.
+ // R represents the category Right to Left character.
+ // AL represents the category Arabic Letter.
+ // AN represents the category Arabic Number.
+ // EN represents the category European Number.
static final byte B = Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR;
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;
static final byte AN = Character.DIRECTIONALITY_ARABIC_NUMBER;
static final byte EN = Character.DIRECTIONALITY_EUROPEAN_NUMBER;
+
static final char LRM = 0x200E;
static final char RLM = 0x200F;
static final char LRE = 0x202A;
@@ -42,7 +54,6 @@ public class STextImpl {
static final int PREFIX_LENGTH = 2;
static final int SUFFIX_LENGTH = 2;
static final int FIXES_LENGTH = PREFIX_LENGTH + SUFFIX_LENGTH;
- static final int DIRPROPS_ADD = 2;
static final int OFFSETS_SHIFT = 3;
static final int[] EMPTY_INT_ARRAY = new int[0];
static final STextEnvironment IGNORE_ENVIRONMENT = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE);
@@ -54,7 +65,7 @@ public class STextImpl {
// nothing to do
}
- static long computeNextLocation(STextProcessor processor, STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] locations, int[] state, int curPos) {
+ static long computeNextLocation(STextProcessor processor, STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] locations, int[] state, int curPos) {
String separators = processor.getSeparators(environment, text, dirProps);
int separCount = separators.length();
int specialsCount = processor.getSpecialsCount(environment, text, dirProps);
@@ -93,105 +104,21 @@ public class STextImpl {
return nextLocation + (((long) idxLocation) << 32);
}
- static int getCurOrient(STextEnvironment environment, String text, byte[] dirProps) {
- int orient = environment.getOrientation();
- if ((orient & STextEnvironment.ORIENT_CONTEXTUAL_LTR) == 0) {
- // absolute orientation
- return orient;
- }
- // contextual orientation
- int len = text.length();
- byte dirProp;
- for (int i = 0; i < len; i++) {
- // In the following lines, B, L, R and AL represent bidi categories
- // as defined in the Unicode Bidirectional Algorithm
- // ( http://www.unicode.org/reports/tr9/ ).
- // B represents the category Block Separator.
- // L represents the category Left to Right character.
- // R represents the category Right to Left character.
- // AL represents the category Arabic Letter.
- dirProp = dirProps[i];
- if (dirProp == 0) {
- dirProp = Character.getDirectionality(text.charAt(i));
- if (dirProp == B) // B char resolves to L or R depending on orientation
- continue;
- dirProps[i] = (byte) (dirProp + DIRPROPS_ADD);
- } else {
- dirProp -= DIRPROPS_ADD;
- }
- if (dirProp == L)
- return STextEnvironment.ORIENT_LTR;
- if (dirProp == R || dirProp == AL)
- return STextEnvironment.ORIENT_RTL;
- }
- // return the default orientation corresponding to the contextual orientation
- return orient & 1;
- }
-
- /**
- * @see STextEngine#getCurDirection STextEngine.getCurDirection
- */
- public static int getCurDirection(STextProcessor processor, STextEnvironment environment, String text, byte[] dirProps) {
- return processor.getDirection(environment, text, dirProps);
- }
-
- /**
- * @see STextProcessor#getDirProp STextProcessor.getDirProp
- */
- public static byte getDirProp(String text, byte[] dirProps, int index) {
- byte dirProp = dirProps == null ? 0 : dirProps[index];
- if (dirProp == 0) {
- // In the following lines, B, L and R represent bidi categories
- // as defined in the Unicode Bidirectional Algorithm
- // ( http://www.unicode.org/reports/tr9/ ).
- // B represents the category Block Separator.
- // L represents the category Left to Right character.
- // R represents the category Right to Left character.
- dirProp = Character.getDirectionality(text.charAt(index));
- if (dirProp == B && dirProps != null) {
- // the last entry of dirProps contains the current component orientation
- byte orient = dirProps[dirProps.length - 1];
- if (orient == -1)
- return B;
- dirProp = orient == STextEnvironment.ORIENT_RTL ? R : L;
- }
- if (dirProps != null)
- dirProps[index] = (byte) (dirProp + DIRPROPS_ADD);
- return dirProp;
- }
- return (byte) (dirProp - DIRPROPS_ADD);
- }
-
- /**
- * @see STextProcessor#setDirProp STextProcessor.setDirProp
- */
- public static void setDirProp(byte[] dirProps, int index, byte dirProp) {
- dirProps[index] = (byte) (dirProp + DIRPROPS_ADD);
- }
-
/**
* @see STextProcessor#processSeparator STextProcessor.processSeparator
*/
- public static void processSeparator(String text, byte[] dirProps, int[] offsets, int separLocation) {
- // In this method, L, R, AL, AN and EN represent bidi categories
- // as defined in the Unicode Bidirectional Algorithm
- // ( http://www.unicode.org/reports/tr9/ ).
- // L represents the category Left to Right character.
- // R represents the category Right to Left character.
- // AL represents the category Arabic Letter.
- // AN represents the category Arabic Number.
- // EN represents the category European Number.
+ public static void processSeparator(String text, STextDirections dirProps, int[] offsets, int separLocation) {
int len = text.length();
// offsets[2] contains the structured text direction
if (offsets[2] == STextEngine.DIR_RTL) {
// the structured text base direction is RTL
for (int i = separLocation - 1; i >= 0; i--) {
- byte dirProp = getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == R || dirProp == AL)
return;
if (dirProp == L) {
for (int j = separLocation; j < len; j++) {
- dirProp = getDirProp(text, dirProps, j);
+ dirProp = dirProps.getOrientationAt(j);
if (dirProp == R || dirProp == AL)
return;
if (dirProp == L || dirProp == EN) {
@@ -208,12 +135,12 @@ public class STextImpl {
// the structured text base direction is LTR
boolean doneAN = false;
for (int i = separLocation - 1; i >= 0; i--) {
- byte dirProp = getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == L)
return;
if (dirProp == R || dirProp == AL) {
for (int j = separLocation; j < len; j++) {
- dirProp = getDirProp(text, dirProps, j);
+ dirProp = dirProps.getOrientationAt(j);
if (dirProp == L)
return;
if (dirProp == R || dirProp == EN || dirProp == AL || dirProp == AN) {
@@ -225,7 +152,7 @@ public class STextImpl {
}
if (dirProp == AN && !doneAN) {
for (int j = separLocation; j < len; j++) {
- dirProp = getDirProp(text, dirProps, j);
+ dirProp = dirProps.getOrientationAt(j);
if (dirProp == L)
return;
if (dirProp == AL || dirProp == AN || dirProp == R) {
@@ -285,7 +212,7 @@ public class STextImpl {
int len = text.length();
if (len == 0)
return text;
- byte[] dirProps = new byte[len + 1];
+ STextDirections dirProps = new STextDirections(text);
int[] offsets = leanToFullCommon(processor, environment, text, state, dirProps);
int prefixLength = offsets[1];
int count = offsets[0] - OFFSETS_SHIFT;
@@ -336,7 +263,7 @@ public class STextImpl {
int len = text.length();
if (len == 0)
return EMPTY_INT_ARRAY;
- byte[] dirProps = new byte[len + 1];
+ STextDirections dirProps = new STextDirections(text);
int[] offsets = leanToFullCommon(processor, environment, text, state, dirProps);
int prefixLength = offsets[1];
int[] map = new int[len];
@@ -359,7 +286,7 @@ public class STextImpl {
int len = text.length();
if (len == 0)
return EMPTY_INT_ARRAY;
- byte[] dirProps = new byte[len + 1];
+ STextDirections dirProps = new STextDirections(text);
int[] offsets = leanToFullCommon(processor, environment, text, state, dirProps);
// offsets[0] contains the number of used entries
int count = offsets[0] - OFFSETS_SHIFT;
@@ -368,7 +295,7 @@ public class STextImpl {
return result;
}
- static int[] leanToFullCommon(STextProcessor processor, STextEnvironment environment, String text, int[] state, byte[] dirProps) {
+ static int[] leanToFullCommon(STextProcessor processor, STextEnvironment environment, String text, int[] state, STextDirections dirProps) {
if (environment == null)
environment = STextEnvironment.DEFAULT;
if (state == null) {
@@ -376,9 +303,7 @@ public class STextImpl {
state[0] = STextEngine.STATE_INITIAL;
}
int len = text.length();
- // dirProps: 1 byte for each char in text, + 1 byte = current orientation
- int orient = getCurOrient(environment, text, dirProps);
- dirProps[len] = (byte) orient;
+ int orient = dirProps.getBaseOrientation(environment);
int direction = processor.getDirection(environment, text, dirProps);
// offsets of marks to add. Entry 0 is the number of used slots;
// entry 1 is reserved to pass prefixLength.
@@ -428,8 +353,7 @@ public class STextImpl {
offsets[1] = 0;
else {
// recompute orient since it may have changed if contextual
- orient = getCurOrient(environment, text, dirProps);
- dirProps[len] = (byte) orient;
+ orient = dirProps.getBaseOrientation(environment);
if (orient == direction && orient != STextEnvironment.ORIENT_UNKNOWN)
offsets[1] = 0;
else if ((environment.getOrientation() & STextEnvironment.ORIENT_CONTEXTUAL_LTR) != 0)
@@ -452,7 +376,7 @@ public class STextImpl {
state = new int[1];
state[0] = STextEngine.STATE_INITIAL;
}
- int dir = processor.getDirection(environment, text, null);
+ int dir = processor.getDirection(environment, text, new STextDirections(text));
char curMark = MARKS[dir];
char curEmbed = EMBEDS[dir];
int i; // used as loop index
@@ -544,7 +468,7 @@ public class STextImpl {
return EMPTY_INT_ARRAY;
String lean = fullToLeanText(processor, environment, full, state);
int lenLean = lean.length();
- int dir = processor.getDirection(environment, lean, null);
+ int dir = processor.getDirection(environment, lean, new STextDirections(lean));
char curMark = MARKS[dir];
char curEmbed = EMBEDS[dir];
int[] map = new int[lenFull];
@@ -581,18 +505,19 @@ public class STextImpl {
offsets[0] = OFFSETS_SHIFT;
int lenLean = lean.length();
int idxLean, idxFull;
+ STextDirections dirProps = new STextDirections(full);
// lean must be a subset of Full, so we only check on iLean < leanLen
for (idxLean = idxFull = 0; idxLean < lenLean; idxFull++) {
if (full.charAt(idxFull) == lean.charAt(idxLean))
idxLean++;
else {
offsets = ensureRoomInOffsets(offsets);
- insertMark(lean, null, offsets, idxFull);
+ insertMark(lean, dirProps, offsets, idxFull);
}
}
for (; idxFull < lenFull; idxFull++) {
offsets = ensureRoomInOffsets(offsets);
- insertMark(lean, null, offsets, idxFull);
+ insertMark(lean, dirProps, offsets, idxFull);
}
int[] result = new int[offsets[0] - OFFSETS_SHIFT];
System.arraycopy(offsets, OFFSETS_SHIFT, result, 0, result.length);
@@ -612,7 +537,7 @@ public class STextImpl {
/**
* @see STextProcessor#insertMark STextProcessor.insertMark
*/
- public static void insertMark(String text, byte[] dirProps, int[] offsets, int offset) {
+ public static void insertMark(String text, STextDirections dirProps, int[] offsets, int offset) {
int count = offsets[0];// number of used entries
int index = count - 1; // index of greatest member <= offset
// look up after which member the new offset should be inserted
@@ -634,17 +559,9 @@ public class STextImpl {
if (dirProps == null || offset < 1)
return;
- byte dirProp = getDirProp(text, dirProps, offset);
+ byte dirProp = dirProps.getOrientationAt(offset);
// if the current char is a strong one or a digit, we change the
// dirProp of the previous char to account for the inserted mark.
- // In the following lines, L, R, AL, AN and EN represent bidi categories
- // as defined in the Unicode Bidirectional Algorithm
- // ( http://www.unicode.org/reports/tr9/ ).
- // L represents the category Left to Right character.
- // R represents the category Right to Left character.
- // AL represents the category Arabic Letter.
- // AN represents the category Arabic Number.
- // EN represents the category European Number.
if (dirProp == L || dirProp == R || dirProp == AL || dirProp == EN || dirProp == AN)
index = offset - 1;
else
@@ -652,7 +569,7 @@ public class STextImpl {
index = offset;
int dir = offsets[2]; // current structured text direction
- setDirProp(dirProps, index, STRONGS[dir]);
+ dirProps.setOrientationAt(index, STRONGS[dir]);
return;
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java
index 2407a7b..effffb3 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/STextSingle.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.bidi.internal;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -40,7 +41,7 @@ public class STextSingle extends STextProcessor {
*
* @see #getSeparators getSeparators
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
return text.indexOf(this.getSeparators(environment, text, dirProps).charAt(0), fromIndex);
}
@@ -50,7 +51,7 @@ public class STextSingle extends STextProcessor {
*
* @return the length of <code>text</code>.
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
return text.length();
}
@@ -60,7 +61,7 @@ public class STextSingle extends STextProcessor {
*
* @return 1.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 1;
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java
index 2b7cb61..bed40f5 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextEmail.java
@@ -12,7 +12,7 @@ package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
-import org.eclipse.equinox.bidi.custom.STextProcessor;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.internal.STextDelimsEsc;
/**
@@ -38,7 +38,7 @@ public class STextEmail extends STextDelimsEsc {
* </ul>
* Otherwise, returns {@link STextEngine#DIR_LTR DIR_LTR}.
*/
- public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getDirection(STextEnvironment environment, String text, STextDirections dirProps) {
String language = environment.getLanguage();
if (!language.equals("ar")) //$NON-NLS-1$
return STextEngine.DIR_LTR;
@@ -47,7 +47,7 @@ public class STextEmail extends STextDelimsEsc {
if (domainStart < 0)
domainStart = 0;
for (int i = domainStart; i < text.length(); i++) {
- byte dirProp = STextProcessor.getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == AL || dirProp == R)
return STextEngine.DIR_RTL;
}
@@ -57,7 +57,7 @@ public class STextEmail extends STextDelimsEsc {
/**
* @return 2 as number of special cases handled by this processor.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 2;
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
index 5562e41..6c57928 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextJava.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
import org.eclipse.equinox.bidi.internal.STextActivator;
@@ -45,7 +46,7 @@ public class STextJava extends STextProcessor {
/**
* @return 4 as the number of special cases handled by this processor.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 4;
}
@@ -58,7 +59,7 @@ public class STextJava extends STextProcessor {
* <li>comments starting with slash-slash</li>
* </ol>
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
switch (caseNumber) {
case 1 : /* space */
return text.indexOf(' ', fromIndex);
@@ -82,7 +83,7 @@ public class STextJava extends STextProcessor {
* <li>skip until after a line separator</li>
* </ol>
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
int location, counter, i;
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
@@ -90,7 +91,7 @@ public class STextJava extends STextProcessor {
case 1 : /* space */
separLocation++;
while (separLocation < text.length() && text.charAt(separLocation) == ' ') {
- STextProcessor.setDirProp(dirProps, separLocation, WS);
+ dirProps.setOrientationAt(separLocation, WS);
separLocation++;
}
return separLocation;
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java
index 450aef9..6b3768b 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextMath.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -40,13 +41,13 @@ public class STextMath extends STextProcessor {
* </ul>
* Otherwise, returns {@link STextEngine#DIR_LTR DIR_LTR}.
*/
- public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getDirection(STextEnvironment environment, String text, STextDirections dirProps) {
String language = environment.getLanguage();
if (!language.equals("ar")) //$NON-NLS-1$
return STextEngine.DIR_LTR;
boolean flagAN = false;
for (int i = 0; i < text.length(); i++) {
- byte dirProp = getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == AL)
return STextEngine.DIR_RTL;
if (dirProp == L || dirProp == R)
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java
index 2dfdf66..36c76fd 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextRegex.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
/**
@@ -68,7 +69,7 @@ public class STextRegex extends STextProcessor {
*
* @return the number of special cases for this processor.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return maxSpecial;
}
@@ -76,7 +77,7 @@ public class STextRegex extends STextProcessor {
* This method locates occurrences of the syntactic strings and of
* R, AL, EN, AN characters.
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
// In this method, L, R, AL, AN and EN represent bidi categories
// as defined in the Unicode Bidirectional Algorithm
// ( http://www.unicode.org/reports/tr9/ ).
@@ -112,18 +113,18 @@ public class STextRegex extends STextProcessor {
fromIndex = 1;
// look for R, AL, AN, EN which are potentially needing a mark
for (; fromIndex < text.length(); fromIndex++) {
- dirProp = STextProcessor.getDirProp(text, dirProps, fromIndex);
+ dirProp = dirProps.getOrientationAt(fromIndex);
// R and AL will always be examined using processSeparator()
if (dirProp == R || dirProp == AL)
return fromIndex;
if (dirProp == EN || dirProp == AN) {
// no need for a mark after the first digit in a number
- if (STextProcessor.getDirProp(text, dirProps, fromIndex - 1) == dirProp)
+ if (dirProps.getOrientationAt(fromIndex - 1) == dirProp)
continue;
for (int i = fromIndex - 1; i >= 0; i--) {
- dirProp = STextProcessor.getDirProp(text, dirProps, i);
+ dirProp = dirProps.getOrientationAt(i);
// after a L char, no need for a mark
if (dirProp == L)
continue;
@@ -144,7 +145,7 @@ public class STextRegex extends STextProcessor {
/**
* This method process the special cases.
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
int location;
switch (caseNumber) {
@@ -203,7 +204,7 @@ public class STextRegex extends STextProcessor {
return text.length();
}
// set the dirProp for the "E" to L (Left to Right character)
- STextProcessor.setDirProp(dirProps, location + 1, L);
+ dirProps.setOrientationAt(location + 1, L);
return location + 2;
case 18 : /* R, AL, AN, EN */
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
@@ -226,12 +227,12 @@ public class STextRegex extends STextProcessor {
* </ul>
* Otherwise, returns {@link STextEngine#DIR_LTR DIR_LTR}.
*/
- public int getDirection(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getDirection(STextEnvironment environment, String text, STextDirections dirProps) {
String language = environment.getLanguage();
if (!language.equals("ar")) //$NON-NLS-1$
return STextEngine.DIR_LTR;
for (int i = 0; i < text.length(); i++) {
- byte dirProp = getDirProp(text, dirProps, i);
+ byte dirProp = dirProps.getOrientationAt(i);
if (dirProp == AL || dirProp == R)
return STextEngine.DIR_RTL;
if (dirProp == L)
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
index 971a7d8..9446545 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextSql.java
@@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEngine;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.custom.STextProcessor;
import org.eclipse.equinox.bidi.internal.STextActivator;
@@ -45,7 +46,7 @@ public class STextSql extends STextProcessor {
/**
* @return 5 as the number of special cases handled by this processor.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 5;
}
@@ -59,7 +60,7 @@ public class STextSql extends STextProcessor {
* <li>comments starting with hyphen-hyphen</li>
* </ol>
*/
- public int indexOfSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int caseNumber, int fromIndex) {
+ public int indexOfSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int caseNumber, int fromIndex) {
switch (caseNumber) {
case 1 : /* space */
return text.indexOf(" ", fromIndex); //$NON-NLS-1$
@@ -86,7 +87,7 @@ public class STextSql extends STextProcessor {
* <li>skip until after a line separator</li>
* </ol>
*/
- public int processSpecial(STextEnvironment environment, String text, byte[] dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
+ public int processSpecial(STextEnvironment environment, String text, STextDirections dirProps, int[] offsets, int[] state, int caseNumber, int separLocation) {
int location;
STextProcessor.processSeparator(text, dirProps, offsets, separLocation);
@@ -94,7 +95,7 @@ public class STextSql extends STextProcessor {
case 1 : /* space */
separLocation++;
while (separLocation < text.length() && text.charAt(separLocation) == ' ') {
- STextProcessor.setDirProp(dirProps, separLocation, WS);
+ dirProps.setOrientationAt(separLocation, WS);
separLocation++;
}
return separLocation;
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java
index 67ec4c5..cef45e5 100644
--- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java
+++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/internal/consumable/STextXPath.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.bidi.internal.consumable;
import org.eclipse.equinox.bidi.STextEnvironment;
+import org.eclipse.equinox.bidi.custom.STextDirections;
import org.eclipse.equinox.bidi.internal.STextDelims;
/**
@@ -25,7 +26,7 @@ public class STextXPath extends STextDelims {
/**
* @return 2 as the number of special cases handled by this processor.
*/
- public int getSpecialsCount(STextEnvironment environment, String text, byte[] dirProps) {
+ public int getSpecialsCount(STextEnvironment environment, String text, STextDirections dirProps) {
return 2;
}