diff options
| author | Matitiahu Allouche | 2011-08-19 13:27:13 +0000 |
|---|---|---|
| committer | Oleg Besedin | 2011-08-19 13:27:13 +0000 |
| commit | 56b28d1cfe2ae47ccb17b042830dcb95de6dcde8 (patch) | |
| tree | 298910fc8e19870a2dea81d790f96a55d71102eb | |
| parent | 443d39df762926eff2c600a9cfd0f1e620dd7cb8 (diff) | |
| download | rt.equinox.bundles-56b28d1cfe2ae47ccb17b042830dcb95de6dcde8.tar.gz rt.equinox.bundles-56b28d1cfe2ae47ccb17b042830dcb95de6dcde8.tar.xz rt.equinox.bundles-56b28d1cfe2ae47ccb17b042830dcb95de6dcde8.zip | |
Bug 183164 - [Implementation for] Display of Complex Expressions
Containing Bidirectional Text
24 files changed, 273 insertions, 490 deletions
diff --git a/bundles/org.eclipse.equinox.bidi.tests/plugin.xml b/bundles/org.eclipse.equinox.bidi.tests/plugin.xml index dcd6a395c..5cefcf73b 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/plugin.xml +++ b/bundles/org.eclipse.equinox.bidi.tests/plugin.xml @@ -7,38 +7,9 @@ <typeDescription class="org.eclipse.equinox.bidi.internal.tests.STextTest" description="Test" - type="test"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandler1" - description="Test Handler 1" - type="test.Handler1"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandler2" - description="Test Handler 2" - type="test.Handler2"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandler3" - description="Test Handler 3" - type="test.Handler3"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandlerMyCommaRL" - description="Test my comma RL" - type="test.MyCommaRL"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandlerMyCommaRR" - description="Test my comma RR" - type="test.MyCommaRR"> - </typeDescription> - <typeDescription - class="org.eclipse.equinox.bidi.internal.tests.TestHandlerMyCommaLL" - description="Test my comma LL" - type="test.MyCommaLL"> + type="test.ID"> </typeDescription> + </extension> </plugin> diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensibilityTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensibilityTest.java index 0e76dac78..2fbbf3653 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensibilityTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensibilityTest.java @@ -21,27 +21,8 @@ import org.eclipse.equinox.bidi.custom.STextTypeHandler; */ public class STextExtensibilityTest extends STextTestBase { - public void testBaseContributions() { - String[] types = STextTypeHandlerFactory.getAllHandlerIDs(); - assertNotNull(types); - assertTrue(types.length > 0); - - // check one of the types that we know should be there - assertTrue(isTypePresent(types, "regex")); - - STextTypeHandler handler = STextTypeHandlerFactory.getHandler("regex"); - assertNotNull(handler); - } - public void testOtherContributions() { - String[] types = STextTypeHandlerFactory.getAllHandlerIDs(); - assertNotNull(types); - assertTrue(types.length > 0); - - // check the type added by the test bundle - assertTrue(isTypePresent(types, "test")); - - STextTypeHandler handler = STextTypeHandlerFactory.getHandler("test"); + STextTypeHandler handler = STextTypeHandlerFactory.getHandler("test.ID"); assertNotNull(handler); handler = STextTypeHandlerFactory.getHandler("badtest"); @@ -52,18 +33,11 @@ public class STextExtensibilityTest extends STextTestBase { lean = toUT16(data); handler = STextTypeHandlerFactory.getHandler("test"); - ISTextExpert expert = STextExpertFactory.getExpert("test"); + ISTextExpert expert = STextExpertFactory.getExpert("test.ID"); full = expert.leanToFullText(lean); model = "ABC@.DEF@:HOST@-COM@=HELLO"; assertEquals("Test 'test' plugin", model, toPseudo(full)); } - private boolean isTypePresent(String[] types, String type) { - for (int i = 0; i < types.length; i++) { - if (type.equalsIgnoreCase(types[i])) - return true; - } - return false; - } } diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensionsTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensionsTest.java index a01e7a672..e136165a7 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensionsTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextExtensionsTest.java @@ -66,7 +66,7 @@ public class STextExtensionsTest extends STextTestBase { expert = STextExpertFactory.getExpert(STextTypeHandlerFactory.FILE, env); doTest1("File #1", "c:\\A\\B\\FILE.EXT", "c:\\A@\\B@\\FILE@.EXT"); - expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.JAVA, env); + expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA, env); doTest1("Java #1", "A = B + C;", "A@ = B@ + C;"); doTest1("Java #2", "A = B + C;", "A@ = B@ + C;"); doTest1("Java #3", "A = \"B+C\"+D;", "A@ = \"B+C\"@+D;"); @@ -83,7 +83,7 @@ public class STextExtensionsTest extends STextTestBase { doTest1("Property #1", "NAME=VAL1,VAL2", "NAME@=VAL1,VAL2"); doTest1("Property #2", "NAME=VAL1,VAL2=VAL3", "NAME@=VAL1,VAL2=VAL3"); - expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.REGEXP, env); + expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.REGEXP, env); data = toUT16("ABC(?") + "#" + toUT16("DEF)GHI"); doTest2("Regex #0.0", data, "A@B@C@(?#DEF)@G@H@I"); data = toUT16("ABC(?") + "#" + toUT16("DEF"); @@ -167,7 +167,7 @@ public class STextExtensionsTest extends STextTestBase { doTest2("Regex #16.2", data, "<&#HI\\eJKL&^"); env = envHebrew; - expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.SQL, env); + expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.SQL, env); doTest1("SQL #0", "abc GHI", "abc GHI"); doTest1("SQL #1", "abc DEF GHI", "abc DEF@ GHI"); doTest1("SQL #2", "ABC, DEF, GHI", "ABC@, DEF@, GHI"); diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java index bed6e1f3d..4bdf409d4 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextFullToLeanTest.java @@ -67,14 +67,14 @@ public class STextFullToLeanTest extends STextTestBase { data = "update \"AB_CDE\" set \"COL1\"@='01', \"COL2\"@='02' /* GH IJK"; text = toUT16(data); - ISTextExpert expertLTR = STextExpertFactory.getPrivateExpert(type, envLTR); + ISTextExpert expertLTR = STextExpertFactory.getStatefulExpert(type, envLTR); expertLTR.clearState(); lean = expertLTR.fullToLeanText(text); state1 = expertLTR.getState(); model = "update \"AB_CDE\" set \"COL1\"='01', \"COL2\"='02' /* GH IJK"; assertEquals(msg + "LTR lean", model, toPseudo(lean)); - ISTextExpert expertLTR2 = STextExpertFactory.getPrivateExpert(type, envLTR); + ISTextExpert expertLTR2 = STextExpertFactory.getStatefulExpert(type, envLTR); expertLTR2.clearState(); full = expertLTR2.leanToFullText(lean); 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 917202436..a816c6f77 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 @@ -11,24 +11,65 @@ package org.eclipse.equinox.bidi.internal.tests; -import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.STextTypeHandlerFactory; import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.custom.STextCharTypes; +import org.eclipse.equinox.bidi.custom.STextTypeHandler; /** * Tests most public methods of BidiComplexEngine */ public class STextMethodsTest extends STextTestBase { - final static int LTR = STextDirection.DIR_LTR; - final static int RTL = STextDirection.DIR_RTL; - final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR); - final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL); - final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL); - final static STextEnvironment envIGN = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); - final static STextEnvironment envCLR = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_LTR); - final static STextEnvironment envCRL = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_RTL); - final static STextEnvironment envERR = new STextEnvironment(null, false, 9999); + private final static int LTR = ISTextExpert.DIR_LTR; + private final static int RTL = ISTextExpert.DIR_RTL; + private final static STextEnvironment envLTR = new STextEnvironment(null, false, STextEnvironment.ORIENT_LTR); + private final static STextEnvironment envRTL = new STextEnvironment(null, false, STextEnvironment.ORIENT_RTL); + private final static STextEnvironment envRTLMIR = new STextEnvironment(null, true, STextEnvironment.ORIENT_RTL); + private final static STextEnvironment envIGN = new STextEnvironment(null, false, STextEnvironment.ORIENT_IGNORE); + private final static STextEnvironment envCLR = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_LTR); + private final static STextEnvironment envCRL = new STextEnvironment(null, false, STextEnvironment.ORIENT_CONTEXTUAL_RTL); + private final static STextEnvironment envERR = new STextEnvironment(null, false, 9999); + private final static TestHandlerMyComma testMyCommaLL = new TestHandlerMyComma(LTR, LTR); + private final static TestHandlerMyComma testMyCommaRR = new TestHandlerMyComma(RTL, RTL); + private final static TestHandlerMyComma testMyCommaRL = new TestHandlerMyComma(RTL, LTR); + + private static class TestHandlerMyComma extends STextTypeHandler { + + private final static byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC; + + final int dirArabic; + final int dirHebrew; + + public TestHandlerMyComma(int dirArabic, int dirHebrew) { + this.dirArabic = dirArabic; + this.dirHebrew = dirHebrew; + } + + public String getSeparators(ISTextExpert expert) { + return ","; //$NON-NLS-1$ + } + + public boolean skipProcessing(ISTextExpert expert, String text, STextCharTypes charTypes) { + byte charType = charTypes.getBidiTypeAt(0); + if (charType == AL) + return true; + return false; + } + + public int getDirection(ISTextExpert expert, String text) { + return getDirection(expert, text, new STextCharTypes(expert, text)); + } + + public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) { + for (int i = 0; i < text.length(); i++) { + byte charType = charTypes.getBidiTypeAt(i); + if (charType == AL) + return dirArabic; + } + return dirHebrew; + } + } private void doTestTools() { @@ -47,7 +88,7 @@ public class STextMethodsTest extends STextTestBase { private void doTestState() { String data, lean, full, model; - ISTextExpert expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.JAVA); + ISTextExpert expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA); data = "A=B+C;/* D=E+F;"; lean = toUT16(data); @@ -88,12 +129,12 @@ public class STextMethodsTest extends STextTestBase { assertEquals("orient #4", STextEnvironment.ORIENT_UNKNOWN, orient); } - private void doTestOrient(String handlerDefID, String label, String data, String resLTR, String resRTL, String resCon) { + private void doTestOrient(STextTypeHandler handler, String label, String data, String resLTR, String resRTL, String resCon) { String full, lean; - ISTextExpert expertLTR = STextExpertFactory.getExpert(handlerDefID, envLTR); - ISTextExpert expertRTL = STextExpertFactory.getExpert(handlerDefID, envRTL); - ISTextExpert expertCRL = STextExpertFactory.getExpert(handlerDefID, envCRL); + ISTextExpert expertLTR = STextExpertFactory.getExpert(handler, envLTR); + ISTextExpert expertRTL = STextExpertFactory.getExpert(handler, envRTL); + ISTextExpert expertCRL = STextExpertFactory.getExpert(handler, envCRL); lean = toUT16(data); full = expertLTR.leanToFullText(lean); @@ -105,13 +146,13 @@ public class STextMethodsTest extends STextTestBase { } private void doTestSkipProcessing() { - doTestOrient("test.MyCommaLL", "Skip #1 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); - doTestOrient("test.MyCommaLL", "Skip #2 ", "#CD,EF", "#CD,EF", ">@#CD,EF@^", "@#CD,EF"); + doTestOrient(testMyCommaLL, "Skip #1 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); + doTestOrient(testMyCommaLL, "Skip #2 ", "#CD,EF", "#CD,EF", ">@#CD,EF@^", "@#CD,EF"); } private void doTestLeanOffsets() { String lean, data, label; - ISTextExpert expert = STextExpertFactory.getPrivateExpert(STextTypeHandlerFactory.JAVA); + ISTextExpert expert = STextExpertFactory.getStatefulExpert(STextTypeHandlerFactory.JAVA); int[] offsets; int[] model; @@ -164,17 +205,17 @@ public class STextMethodsTest extends STextTestBase { private void doTestDirection() { String data, lean, full, model; int dirA, dirH; - ISTextExpert expertRL = STextExpertFactory.getExpert("test.MyCommaRL"); + ISTextExpert expertRL = STextExpertFactory.getExpert(testMyCommaRL, envLTR); dirA = expertRL.getTextDirection(toUT16("###")); dirH = expertRL.getTextDirection(toUT16("ABC")); assertTrue("TestDirection #1", dirA == RTL && dirH == LTR); - ISTextExpert expertRR = STextExpertFactory.getExpert("test.MyCommaRR"); + ISTextExpert expertRR = STextExpertFactory.getExpert(testMyCommaRR, envLTR); dirA = expertRR.getTextDirection(toUT16("###")); dirH = expertRR.getTextDirection(toUT16("ABC")); assertTrue("TestDirection #2", dirA == RTL && dirH == RTL); - ISTextExpert expertLL = STextExpertFactory.getExpert("test.MyCommaLL"); + ISTextExpert expertLL = STextExpertFactory.getExpert(testMyCommaLL, envLTR); lean = toUT16("ABC,#DEF,HOST,com"); full = expertLL.leanToFullText(lean); assertEquals("TestDirection #9 full", "ABC@,#DEF@,HOST,com", toPseudo(full)); @@ -185,7 +226,7 @@ public class STextMethodsTest extends STextTestBase { assertEquals("TestDirection #10 full", "ABC@,DEF@,HOST,com", toPseudo(full)); STextEnvironment environment = new STextEnvironment(null, true, STextEnvironment.ORIENT_LTR); - ISTextExpert expert = STextExpertFactory.getExpert("test.MyCommaRL", environment); + ISTextExpert expert = STextExpertFactory.getExpert(testMyCommaRL, environment); dirA = expert.getTextDirection(toUT16("###")); dirH = expert.getTextDirection(toUT16("ABC")); assertTrue("TestDirection #10.5", dirA == RTL && dirH == LTR); @@ -227,7 +268,7 @@ public class STextMethodsTest extends STextTestBase { data = "ABc,|#DEF,HOST,com"; lean = toUT16(data); - expert = STextExpertFactory.getExpert("test.MyCommaRL", envRTLMIR); + expert = STextExpertFactory.getExpert(testMyCommaRL, envRTLMIR); full = expert.leanToFullText(lean); model = "ABc,|#DEF,HOST,com"; assertEquals("TestDirection #17 full", model, toPseudo(full)); @@ -243,15 +284,16 @@ public class STextMethodsTest extends STextTestBase { doTestOrientation(); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #1 ", "", "", "", ""); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #2 ", "abc", "abc", ">@abc@^", "abc"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH"); - doTestOrient(STextTypeHandlerFactory.COMMA_DELIMITED, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh"); + STextTypeHandler commaHandler = STextTypeHandlerFactory.getHandler(STextTypeHandlerFactory.COMMA_DELIMITED); + doTestOrient(commaHandler, "Methods #1 ", "", "", "", ""); + doTestOrient(commaHandler, "Methods #2 ", "abc", "abc", ">@abc@^", "abc"); + doTestOrient(commaHandler, "Methods #3 ", "ABC", "ABC", ">@ABC@^", "@ABC"); + doTestOrient(commaHandler, "Methods #4 ", "bcd,ef", "bcd,ef", ">@bcd,ef@^", "bcd,ef"); + doTestOrient(commaHandler, "Methods #5 ", "BCD,EF", "BCD@,EF", ">@BCD@,EF@^", "@BCD@,EF"); + doTestOrient(commaHandler, "Methods #6 ", "cde,FG", "cde,FG", ">@cde,FG@^", "cde,FG"); + doTestOrient(commaHandler, "Methods #7 ", "CDE,fg", "CDE,fg", ">@CDE,fg@^", "@CDE,fg"); + doTestOrient(commaHandler, "Methods #8 ", "12..def,GH", "12..def,GH", ">@12..def,GH@^", "12..def,GH"); + doTestOrient(commaHandler, "Methods #9 ", "34..DEF,gh", "34..DEF,gh", ">@34..DEF,gh@^", "@34..DEF,gh"); doTestSkipProcessing(); diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextProcessorTest.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextProcessorTest.java index 3bbec2d4d..a9454f87b 100644 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextProcessorTest.java +++ b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/STextProcessorTest.java @@ -14,6 +14,8 @@ package org.eclipse.equinox.bidi.internal.tests; import java.util.Locale;
import org.eclipse.equinox.bidi.STextProcessor;
import org.eclipse.equinox.bidi.STextTypeHandlerFactory;
+import org.eclipse.equinox.bidi.advanced.ISTextExpert;
+import org.eclipse.equinox.bidi.advanced.STextExpertFactory;
/**
* Tests methods in BidiComplexUtil
@@ -89,15 +91,15 @@ public class STextProcessorTest extends STextTestBase { assertEquals(msg + "lean", resLean, toPseudo(lean));
}
- private void doTest4(String msg, String data, int[] offsets, int direction, boolean affix, String result) {
- String txt = msg + "text=" + data + "\n offsets=" + array_display(offsets) + "\n direction=" + direction + "\n affix=" + affix;
+ private void doTest4(String msg, String data, int[] offsets, int direction, int affixLength, String result) {
+ String txt = msg + "text=" + data + "\n offsets=" + array_display(offsets) + "\n direction=" + direction + "\n affixLength=" + affixLength;
String lean = toUT16(data);
- String full = STextProcessor.insertMarks(lean, offsets, direction, affix);
+ ISTextExpert expert = STextExpertFactory.getExpert();
+ String full = expert.insertMarks(lean, offsets, direction, affixLength);
assertEquals(txt, result, toPseudo(full));
}
public void testSTextProcessor() {
-
// Test process() and deprocess() with default delimiters
doTest1("ABC/DEF/G", ">@ABC@/DEF@/G@^");
// Test process() and deprocess() with specified delimiters
@@ -112,13 +114,13 @@ public class STextProcessorTest extends STextTestBase { doTest3("Util #3.2 - ", "", "");
doTest3("Util #3.3 - ", ">@DEF@^", ">@DEF@^", "DEF");
// Test insertMarks()
- doTest4("Util #4.1 - ", "ABCDEFG", new int[] {3, 6}, 0, false, "ABC@DEF@G");
- doTest4("Util #4.2 - ", "ABCDEFG", new int[] {3, 6}, 0, true, ">@ABC@DEF@G@^");
- doTest4("Util #4.3 - ", "ABCDEFG", new int[] {3, 6}, 1, false, "ABC&DEF&G");
- doTest4("Util #4.4 - ", "ABCDEFG", new int[] {3, 6}, 1, true, "<&ABC&DEF&G&^");
- doTest4("Util #4.5 - ", "", new int[] {3, 6}, 0, false, "");
- doTest4("Util #4.6 - ", "", new int[] {3, 6}, 0, true, "");
- doTest4("Util #4.7 - ", "ABCDEFG", null, 1, false, "ABCDEFG");
- doTest4("Util #4.8 - ", "ABCDEFG", null, 1, true, "<&ABCDEFG&^");
+ doTest4("Util #4.1 - ", "ABCDEFG", new int[] {3, 6}, 0, 0, "ABC@DEF@G");
+ doTest4("Util #4.2 - ", "ABCDEFG", new int[] {3, 6}, 0, 2, ">@ABC@DEF@G@^");
+ doTest4("Util #4.3 - ", "ABCDEFG", new int[] {3, 6}, 1, 0, "ABC&DEF&G");
+ doTest4("Util #4.4 - ", "ABCDEFG", new int[] {3, 6}, 1, 2, "<&ABC&DEF&G&^");
+ doTest4("Util #4.5 - ", "", new int[] {3, 6}, 0, 0, "");
+ doTest4("Util #4.6 - ", "", new int[] {3, 6}, 0, 2, "");
+ doTest4("Util #4.7 - ", "ABCDEFG", null, 1, 0, "ABCDEFG");
+ doTest4("Util #4.8 - ", "ABCDEFG", null, 1, 2, "<&ABCDEFG&^");
}
}
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 0166a2dc5..3c8b7e553 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 @@ -12,12 +12,63 @@ package org.eclipse.equinox.bidi.internal.tests; import org.eclipse.equinox.bidi.advanced.*; +import org.eclipse.equinox.bidi.custom.*; /** * Test edge conditions. */ public class STextSomeMoreTest extends STextTestBase { + private class TestHandler1 extends STextTypeHandler { + + public TestHandler1() { + //empty constructor + } + + public int getSpecialsCount(ISTextExpert expert) { + return 1; + } + + public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) { + return fromIndex; + } + + public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) { + int len = text.length(); + for (int i = len - 1; i >= 0; i--) { + STextTypeHandler.insertMark(text, charTypes, offsets, i); + STextTypeHandler.insertMark(text, charTypes, offsets, i); + } + return len; + } + } + + private class TestHandler2 extends STextTypeHandler { + + public TestHandler2() { + //empty constructor + } + + public int getSpecialsCount(ISTextExpert expert) { + return 1; + } + } + + private class TestHandler3 extends STextTypeHandler { + + public TestHandler3() { + //empty constructor + } + + public int getSpecialsCount(ISTextExpert expert) { + return 1; + } + + public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) { + return fromIndex; + } + } + final static STextEnvironment env1 = new STextEnvironment("en_US", false, STextEnvironment.ORIENT_LTR); final static STextEnvironment env2 = new STextEnvironment("he", false, STextEnvironment.ORIENT_LTR); @@ -25,11 +76,13 @@ public class STextSomeMoreTest extends STextTestBase { assertFalse(env1.isProcessingNeeded()); assertTrue(env2.isProcessingNeeded()); - ISTextExpert expert1 = STextExpertFactory.getExpert("test.Handler1", env1); + STextTypeHandler handler1 = new TestHandler1(); + ISTextExpert expert1 = STextExpertFactory.getExpert(handler1, env1); String full = expert1.leanToFullText("abcd"); assertEquals("@a@b@c@d", toPseudo(full)); - ISTextExpert expert2 = STextExpertFactory.getExpert("test.Handler2", env1); + STextTypeHandler handler2 = new TestHandler2(); + ISTextExpert expert2 = STextExpertFactory.getExpert(handler2, env1); boolean catchFlag = false; try { full = expert2.leanToFullText("abcd"); @@ -38,8 +91,9 @@ public class STextSomeMoreTest extends STextTestBase { } assertTrue("Catch missing indexOfSpecial", catchFlag); + STextTypeHandler handler3 = new TestHandler3(); + ISTextExpert expert3 = STextExpertFactory.getExpert(handler3, env1); catchFlag = false; - ISTextExpert expert3 = STextExpertFactory.getExpert("test.Handler3", env1); try { full = expert3.leanToFullText("abcd"); } catch (IllegalStateException e) { diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java deleted file mode 100644 index d89881aa2..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler1.java +++ /dev/null @@ -1,34 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.custom.*;
-
-public class TestHandler1 extends STextTypeHandler {
-
- public int getSpecialsCount(ISTextExpert expert) {
- return 1;
- }
-
- public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
- return fromIndex;
- }
-
- public int processSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int separLocation) {
- int len = text.length();
- for (int i = len - 1; i >= 0; i--) {
- STextTypeHandler.insertMark(text, charTypes, offsets, i);
- STextTypeHandler.insertMark(text, charTypes, offsets, i);
- }
- return len;
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler2.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler2.java deleted file mode 100644 index a11563111..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler2.java +++ /dev/null @@ -1,22 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.custom.STextTypeHandler;
-
-public class TestHandler2 extends STextTypeHandler {
-
- public int getSpecialsCount(ISTextExpert expert) {
- return 1;
- }
-
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler3.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler3.java deleted file mode 100644 index 06729b5d7..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandler3.java +++ /dev/null @@ -1,25 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.custom.*;
-
-public class TestHandler3 extends STextTypeHandler {
-
- public int getSpecialsCount(ISTextExpert expert) {
- return 1;
- }
-
- public int indexOfSpecial(ISTextExpert expert, String text, STextCharTypes charTypes, STextOffsets offsets, int caseNumber, int fromIndex) {
- return fromIndex;
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyComma.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyComma.java deleted file mode 100644 index 5e06038f0..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyComma.java +++ /dev/null @@ -1,55 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-import org.eclipse.equinox.bidi.STextDirection;
-import org.eclipse.equinox.bidi.advanced.ISTextExpert;
-import org.eclipse.equinox.bidi.custom.STextCharTypes;
-import org.eclipse.equinox.bidi.custom.STextTypeHandler;
-
-public class TestHandlerMyComma extends STextTypeHandler {
-
- private final static byte AL = Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC;
- protected final static int LTR = STextDirection.DIR_LTR;
- protected final static int RTL = STextDirection.DIR_RTL;
-
- final int dirArabic;
- final int dirHebrew;
-
- public TestHandlerMyComma(int dirArabic, int dirHebrew) {
- this.dirArabic = dirArabic;
- this.dirHebrew = dirHebrew;
- }
-
- public String getSeparators(ISTextExpert expert) {
- return ","; //$NON-NLS-1$
- }
-
- public boolean skipProcessing(ISTextExpert expert, String text, STextCharTypes charTypes) {
- byte charType = charTypes.getBidiTypeAt(0);
- if (charType == AL)
- return true;
- return false;
- }
-
- public int getDirection(ISTextExpert expert, String text) {
- return getDirection(expert, text, new STextCharTypes(expert, text));
- }
-
- public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
- for (int i = 0; i < text.length(); i++) {
- byte charType = charTypes.getBidiTypeAt(i);
- if (charType == AL)
- return dirArabic;
- }
- return dirHebrew;
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaLL.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaLL.java deleted file mode 100644 index c901c8652..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaLL.java +++ /dev/null @@ -1,18 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-public class TestHandlerMyCommaLL extends TestHandlerMyComma {
-
- public TestHandlerMyCommaLL() {
- super(LTR, LTR);
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRL.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRL.java deleted file mode 100644 index 99d51e801..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRL.java +++ /dev/null @@ -1,18 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-public class TestHandlerMyCommaRL extends TestHandlerMyComma {
-
- public TestHandlerMyCommaRL() {
- super(RTL, LTR);
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRR.java b/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRR.java deleted file mode 100644 index aa92a012d..000000000 --- a/bundles/org.eclipse.equinox.bidi.tests/src/org/eclipse/equinox/bidi/internal/tests/TestHandlerMyCommaRR.java +++ /dev/null @@ -1,18 +0,0 @@ -/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.bidi.internal.tests;
-
-public class TestHandlerMyCommaRR extends TestHandlerMyComma {
-
- public TestHandlerMyCommaRR() {
- super(RTL, RTL);
- }
-}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextDirection.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextDirection.java deleted file mode 100644 index 9cb015610..000000000 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextDirection.java +++ /dev/null @@ -1,38 +0,0 @@ -/*******************************************************************************
- * 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.advanced.STextEnvironment;
-
-// TBD combine with STextProcessor; remove duplicates of those two constants
-public interface STextDirection {
-
- /**
- * 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
- * may be different for Arabic and for Hebrew.
- * This constant can appear as value returned by the
- * {@link #getCurDirection getCurDirection} method.
- */
- public int DIR_LTR = 0;
-
- /**
- * Constant specifying that the base direction of a structured text is RTL.
- * The base direction may depend on whether the GUI is
- * {@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.
- */
- public int DIR_RTL = 1;
-
-}
\ No newline at end of file diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessor.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessor.java index 6fe723e46..fcfe7f58a 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessor.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextProcessor.java @@ -27,14 +27,11 @@ public final class STextProcessor { /**
* The default set of separators used to segment a string: dot, colon, slash, backslash.
*/
- public static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$
+ private static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$
// left to right mark
private static final char LRM = '\u200e';
- // left to right mark
- private static final char RLM = '\u200f';
-
// left to right embedding
private static final char LRE = '\u202a';
@@ -51,75 +48,6 @@ public final class STextProcessor { // empty
}
- /**
- * This method adds directional marks to the given text before the characters
- * specified in the given array of offsets. It can be used to add a prefix and/or
- * a suffix of directional formatting characters.
- * <p>
- * The directional marks will be LRMs for structured text strings with LTR base
- * direction and RLMs for strings with RTL base direction.
- * </p><p>
- * If necessary, leading and trailing directional markers (LRE, RLE and PDF) can
- * be added depending on the value of the <code>affix</code> argument.
- * </p>
- * @see ISTextExpert#leanBidiCharOffsets(String)
- *
- * @param text the structured text string
- * @param offsets an array of offsets to characters in <code>text</code>
- * before which an LRM or RLM will be inserted.
- * The array must be sorted in ascending order without duplicates.
- * This argument may be <code>null</code> if there are no marks to add.
- * @param direction the base direction of the structured text.
- * It must be one of the values {@link STextDirection#DIR_LTR}, or
- * {@link STextDirection#DIR_RTL}.
- * @param affix specifies if a prefix and a suffix should be added to
- * the result
- * @return a string corresponding to the source <code>text</code> with
- * directional marks (LRMs or RLMs) added at the specified offsets,
- * and directional formatting characters (LRE, RLE, PDF) added
- * as prefix and suffix if so required.
- */
- public static String insertMarks(String text, int[] offsets, int direction, boolean affix) {
- int textLen = text.length();
- if (textLen == 0)
- return ""; //$NON-NLS-1$
-
- String curPrefix, curSuffix, full;
- char curMark, c;
- char[] fullChars;
- if (direction == STextDirection.DIR_LTR) {
- curMark = LRM;
- curPrefix = "\u202a\u200e"; /* LRE+LRM *///$NON-NLS-1$
- curSuffix = "\u200e\u202c"; /* LRM+PDF *///$NON-NLS-1$
- } else if (direction == STextDirection.DIR_RTL) {
- curMark = RLM;
- curPrefix = "\u202b\u200f"; /* RLE+RLM *///$NON-NLS-1$
- curSuffix = "\u200f\u202c"; /* RLM+PDF *///$NON-NLS-1$
- } else
- throw new IllegalArgumentException();
- // add marks at offsets
- if ((offsets != null) && (offsets.length > 0)) {
- int offLen = offsets.length;
- fullChars = new char[textLen + offLen];
- int added = 0;
- for (int i = 0, j = 0; i < textLen; i++) {
- c = text.charAt(i);
- if ((j < offLen) && (i == offsets[j])) {
- fullChars[i + added] = curMark;
- added++;
- j++;
- }
- fullChars[i + added] = c;
- }
- full = new String(fullChars);
- } else {
- full = text;
- }
- if (affix)
- return curPrefix + full + curSuffix;
- return full;
- }
-
/**
* Process the given text and return a string with appropriate
* directional formatting characters. This is equivalent to calling
@@ -267,4 +195,14 @@ public final class STextProcessor { return expert.fullToLeanText(str);
}
+ /**
+ * Return the string containing all the default separator characters to be
+ * used to segment a given string.
+ *
+ * @return string containing all separators
+ */
+ public static String getDefaultSeparators() {
+ return defaultSeparators;
+ }
+
}
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java index 41701a9e3..5889e9b09 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/STextTypeHandlerFactory.java @@ -101,14 +101,6 @@ final public class STextTypeHandlerFactory { }
/**
- * Retrieve all IDs of registered structured text handlers.
- * @return an array of text handler IDs.
- */
- static public String[] getAllHandlerIDs() {
- return STextTypesCollector.getInstance().getTypes();
- }
-
- /**
* Obtain a structured text handler of a given type.
* @param id string identifying handler
* @return a handler of the required type, or <code>null</code> if the type is unknown
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java index 7e8b130b8..535e27533 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/ISTextExpert.java @@ -248,6 +248,36 @@ public interface ISTextExpert { */
public int[] fullBidiCharOffsets(String text);
+ /**
+ * This method adds directional marks to the given text before the characters
+ * specified in the given array of offsets. It can be used to add a prefix and/or
+ * a suffix of directional formatting characters.
+ * <p>
+ * The directional marks will be LRMs for structured text strings with LTR base
+ * direction and RLMs for strings with RTL base direction.
+ * </p><p>
+ * If necessary, leading and trailing directional markers (LRE, RLE and PDF) can
+ * be added depending on the value of the <code>affix</code> argument.
+ * </p>
+ * @see ISTextExpert#leanBidiCharOffsets(String)
+ *
+ * @param text the structured text string
+ * @param offsets an array of offsets to characters in <code>text</code>
+ * before which an LRM or RLM will be inserted.
+ * The array must be sorted in ascending order without duplicates.
+ * This argument may be <code>null</code> if there are no marks to add.
+ * @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
+ * @return a string corresponding to the source <code>text</code> with
+ * directional marks (LRMs or RLMs) added at the specified offsets,
+ * and directional formatting characters (LRE, RLE, PDF) added
+ * as prefix and suffix if so required.
+ */
+ public String insertMarks(String text, int[] offsets, int direction, int affixLength);
+
/**
* 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,
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java index 9c1626988..9d66c841e 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/advanced/STextExpertFactory.java @@ -12,6 +12,7 @@ package org.eclipse.equinox.bidi.advanced; import java.util.HashMap;
import java.util.Map;
+import org.eclipse.equinox.bidi.STextProcessor;
import org.eclipse.equinox.bidi.STextTypeHandlerFactory;
import org.eclipse.equinox.bidi.custom.STextTypeHandler;
import org.eclipse.equinox.bidi.internal.STextImpl;
@@ -21,7 +22,7 @@ final public class STextExpertFactory { /**
* The default set of separators used to segment a string: dot, colon, slash, backslash.
*/
- private static final String defaultSeparators = ".:/\\"; //$NON-NLS-1$
+ private static final String defaultSeparators = STextProcessor.getDefaultSeparators();
static private Map sharedDefaultExperts = new HashMap(); // String type -> expert
@@ -84,11 +85,11 @@ final public class STextExpertFactory { return new STextImpl(handler, environment, true);
}
- static public ISTextExpert getPrivateExpert(String type) {
- return getPrivateExpert(type, STextEnvironment.DEFAULT);
+ static public ISTextExpert getStatefulExpert(String type) {
+ return getStatefulExpert(type, STextEnvironment.DEFAULT);
}
- static public ISTextExpert getPrivateExpert(String type, STextEnvironment environment) {
+ static public ISTextExpert getStatefulExpert(String type, STextEnvironment environment) {
STextTypeHandler handler = STextTypeHandlerFactory.getHandler(type);
if (handler == null)
return null;
diff --git a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java index af197b5f3..2a53fa77a 100644 --- a/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java +++ b/bundles/org.eclipse.equinox.bidi/src/org/eclipse/equinox/bidi/custom/STextTypeHandler.java @@ -10,7 +10,6 @@ ******************************************************************************/
package org.eclipse.equinox.bidi.custom;
-import org.eclipse.equinox.bidi.STextDirection;
import org.eclipse.equinox.bidi.advanced.ISTextExpert;
import org.eclipse.equinox.bidi.advanced.STextEnvironment;
import org.eclipse.equinox.bidi.internal.STextImpl;
@@ -323,10 +322,10 @@ public class STextTypeHandler { * whether the structured text contains Arabic or Hebrew
* letters.<br>
* The value returned is either
- * {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
+ * {@link ISTextExpert#DIR_LTR DIR_LTR} or {@link ISTextExpert#DIR_RTL DIR_RTL}.
*/
public int getDirection(ISTextExpert expert, String text) {
- return STextDirection.DIR_LTR;
+ return ISTextExpert.DIR_LTR;
}
/**
@@ -352,10 +351,10 @@ public class STextTypeHandler { * whether the structured text contains Arabic or Hebrew
* letters.<br>
* The value returned is either
- * {@link STextDirection#DIR_LTR DIR_LTR} or {@link STextDirection#DIR_RTL DIR_RTL}.
+ * {@link ISTextExpert#DIR_LTR DIR_LTR} or {@link ISTextExpert#DIR_RTL DIR_RTL}.
*/
public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) {
- return STextDirection.DIR_LTR;
+ return ISTextExpert.DIR_LTR;
}
/**
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 412a7b48c..de6a2a7ad 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 @@ -10,7 +10,6 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal; -import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; @@ -125,7 +124,7 @@ public class STextImpl implements ISTextExpert { static public void processSeparator(String text, STextCharTypes charTypes, STextOffsets offsets, int separLocation) { int len = text.length(); int direction = charTypes.getDirection(); - if (direction == STextDirection.DIR_RTL) { + if (direction == DIR_RTL) { // the structured text base direction is RTL for (int i = separLocation - 1; i >= 0; i--) { byte charType = charTypes.getBidiTypeAt(i); @@ -230,44 +229,8 @@ public class STextImpl implements ISTextExpert { STextCharTypes charTypes = new STextCharTypes(this, text); STextOffsets offsets = leanToFullCommon(text, charTypes); int prefixLength = offsets.getPrefixLength(); - int count = offsets.getCount(); - if (count == 0 && prefixLength == 0) - return text; - int newLen = len + count; - if (prefixLength == 1) - newLen++; /* +1 for a mark char */ - else if (prefixLength == 2) - newLen += FIXES_LENGTH; - char[] fullChars = new char[newLen]; - int added = prefixLength; - // add marks at offsets int direction = charTypes.getDirection(); - char curMark = MARKS[direction]; - for (int i = 0, j = 0; i < len; i++) { - char c = text.charAt(i); - if (j < count && i == offsets.getOffset(j)) { - fullChars[i + added] = curMark; - added++; - j++; - } - fullChars[i + added] = c; - } - if (prefixLength > 0) { /* add prefix/suffix ? */ - if (prefixLength == 1) { /* contextual orientation */ - fullChars[0] = curMark; - } else { - // When the orientation is RTL, we need to add EMBED at the - // start of the text and PDF at its end. - // However, because of a bug in Windows' handling of LRE/PDF, - // we add EMBED_PREFIX at the start and EMBED_SUFFIX at the end. - char curEmbed = EMBEDS[direction]; - fullChars[0] = curEmbed; - fullChars[1] = curMark; - fullChars[newLen - 1] = PDF; - fullChars[newLen - 2] = curMark; - } - } - return new String(fullChars); + return insertMarks(text, offsets.getOffsets(), direction, prefixLength); } public int[] leanToFullMap(String text) { @@ -507,4 +470,52 @@ public class STextImpl implements ISTextExpert { offsets.insertOffset(null, idxFull); return offsets.getOffsets(); } + + public String insertMarks(String text, int[] offsets, int direction, int affixLength) { + if (direction != DIR_LTR && direction != DIR_RTL) + throw new IllegalArgumentException("Invalid direction"); //$NON-NLS-1$ + if (affixLength < 0 || affixLength > 2) + throw new IllegalArgumentException("Invalid affix length"); //$NON-NLS-1$ + int count = offsets == null ? 0 : offsets.length; + if (count == 0 && affixLength == 0) + return text; + int textLength = text.length(); + if (textLength == 0) + return text; + int newLen = textLength + count; + if (affixLength == 1) + newLen++; /* +1 for a mark char */ + else if (affixLength == 2) + newLen += FIXES_LENGTH; + char[] fullChars = new char[newLen]; + int added = affixLength; + // add marks at offsets + char curMark = MARKS[direction]; + for (int i = 0, j = 0; i < textLength; i++) { + char c = text.charAt(i); + if (j < count && i == offsets[j]) { + fullChars[i + added] = curMark; + added++; + j++; + } + fullChars[i + added] = c; + } + if (affixLength > 0) { /* add prefix/suffix ? */ + if (affixLength == 1) { /* contextual orientation */ + fullChars[0] = curMark; + } else { + // When the orientation is RTL, we need to add EMBED at the + // start of the text and PDF at its end. + // However, because of a bug in Windows' handling of LRE/PDF, + // we add EMBED_PREFIX at the start and EMBED_SUFFIX at the end. + char curEmbed = EMBEDS[direction]; + fullChars[0] = curEmbed; + fullChars[1] = curMark; + fullChars[newLen - 1] = PDF; + fullChars[newLen - 2] = curMark; + } + } + return new String(fullChars); + } + } 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 3f4796581..0554e7fc4 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 @@ -10,7 +10,6 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.custom.STextCharTypes; import org.eclipse.equinox.bidi.internal.STextDelimsEsc; @@ -32,7 +31,7 @@ public class STextEmail extends STextDelimsEsc { } /** - * @return {@link STextDirection#DIR_RTL DIR_RTL} if the following + * @return {@link ISTextExpert#DIR_RTL DIR_RTL} if the following * conditions are satisfied: * <ul> * <li>The current locale (as expressed by the environment @@ -40,12 +39,12 @@ public class STextEmail extends STextDelimsEsc { * <li>The domain part of the email address contains * at least one RTL character.</li> * </ul> - * Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}. + * Otherwise, returns {@link ISTextExpert#DIR_LTR DIR_LTR}. */ public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) { String language = expert.getEnvironment().getLanguage(); if (!language.equals("ar")) //$NON-NLS-1$ - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; int domainStart; domainStart = text.indexOf('@'); if (domainStart < 0) @@ -53,9 +52,9 @@ public class STextEmail extends STextDelimsEsc { for (int i = domainStart; i < text.length(); i++) { byte charType = charTypes.getBidiTypeAt(i); if (charType == AL || charType == R) - return STextDirection.DIR_RTL; + return ISTextExpert.DIR_RTL; } - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; } /** 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 7336c30ca..e46f8321b 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 @@ -10,7 +10,6 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.custom.STextCharTypes; import org.eclipse.equinox.bidi.custom.STextTypeHandler; @@ -34,7 +33,7 @@ public class STextMath extends STextTypeHandler { } /** - * @return {@link STextDirection#DIR_RTL DIR_RTL} if the following + * @return {@link ISTextExpert#DIR_RTL DIR_RTL} if the following * conditions are satisfied: * <ul> * <li>The current locale (as expressed by the environment @@ -43,24 +42,24 @@ public class STextMath extends STextTypeHandler { * <li>If there is no strong character in the text, there is * at least one Arabic-Indic digit in the text.</li> * </ul> - * Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}. + * Otherwise, returns {@link ISTextExpert#DIR_LTR DIR_LTR}. */ public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) { String language = expert.getEnvironment().getLanguage(); if (!language.equals("ar")) //$NON-NLS-1$ - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; boolean flagAN = false; for (int i = 0; i < text.length(); i++) { byte charType = charTypes.getBidiTypeAt(i); if (charType == AL) - return STextDirection.DIR_RTL; + return ISTextExpert.DIR_RTL; if (charType == L || charType == R) - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; if (charType == AN) flagAN = true; } if (flagAN) - return STextDirection.DIR_RTL; - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_RTL; + return ISTextExpert.DIR_LTR; } } 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 b08db5196..e4849341b 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 @@ -10,7 +10,6 @@ ******************************************************************************/ package org.eclipse.equinox.bidi.internal.consumable; -import org.eclipse.equinox.bidi.STextDirection; import org.eclipse.equinox.bidi.advanced.ISTextExpert; import org.eclipse.equinox.bidi.advanced.STextEnvironment; import org.eclipse.equinox.bidi.custom.*; @@ -226,7 +225,7 @@ public class STextRegex extends STextTypeHandler { } /** - * @return {@link STextDirection#DIR_RTL DIR_RTL} if the following + * @return {@link ISTextExpert#DIR_RTL DIR_RTL} if the following * conditions are satisfied: * <ul> * <li>The current locale (as expressed by the environment @@ -235,23 +234,23 @@ public class STextRegex extends STextTypeHandler { * <li>If there is no strong character in the text, the * GUI is mirrored. * </ul> - * Otherwise, returns {@link STextDirection#DIR_LTR DIR_LTR}. + * Otherwise, returns {@link ISTextExpert#DIR_LTR DIR_LTR}. */ public int getDirection(ISTextExpert expert, String text, STextCharTypes charTypes) { STextEnvironment environment = expert.getEnvironment(); String language = environment.getLanguage(); if (!language.equals("ar")) //$NON-NLS-1$ - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; for (int i = 0; i < text.length(); i++) { byte charType = charTypes.getBidiTypeAt(i); if (charType == AL || charType == R) - return STextDirection.DIR_RTL; + return ISTextExpert.DIR_RTL; if (charType == L) - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_LTR; } if (environment.getMirrored()) - return STextDirection.DIR_RTL; - return STextDirection.DIR_LTR; + return ISTextExpert.DIR_RTL; + return ISTextExpert.DIR_LTR; } } |
