Search in sources :

Example 1 with UnicodeSetSpanner

use of android.icu.text.UnicodeSetSpanner in project j2objc by google.

the class UnicodeSetTest method checkCodePoints.

private void checkCodePoints(String a, String b, CountMethod quantifier, SpanCondition spanCondition, String expectedReplaced, int expectedCount) {
    final String ab = a + b;
    UnicodeSetSpanner m = new UnicodeSetSpanner(new UnicodeSet("[{" + a + "}]"));
    assertEquals("new UnicodeSetSpanner(\"[{" + a + "}]\").countIn(\"" + ab + "\")", expectedCount, callCountIn(m, ab, quantifier, spanCondition));
    if (expectedReplaced == null) {
        expectedReplaced = "-" + b;
    }
    assertEquals("new UnicodeSetSpanner(\"[{" + a + "}]\").replaceFrom(\"" + ab + "\", \"-\")", expectedReplaced, m.replaceFrom(ab, "-", quantifier));
}
Also used : UnicodeSetSpanner(android.icu.text.UnicodeSetSpanner) UnicodeSet(android.icu.text.UnicodeSet)

Example 2 with UnicodeSetSpanner

use of android.icu.text.UnicodeSetSpanner in project j2objc by google.

the class UnicodeSetTest method TestCountIn.

@Test
public void TestCountIn() {
    UnicodeSetSpanner m = new UnicodeSetSpanner(new UnicodeSet("[ab]"));
    checkCountIn(m, CountMethod.MIN_ELEMENTS, SpanCondition.SIMPLE, "abc", 2);
    checkCountIn(m, CountMethod.WHOLE_SPAN, SpanCondition.SIMPLE, "abc", 1);
    checkCountIn(m, CountMethod.MIN_ELEMENTS, SpanCondition.NOT_CONTAINED, "acccb", 3);
}
Also used : UnicodeSetSpanner(android.icu.text.UnicodeSetSpanner) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Example 3 with UnicodeSetSpanner

use of android.icu.text.UnicodeSetSpanner in project j2objc by google.

the class UnicodeSetTest method TestReplaceAndDelete.

@Test
public void TestReplaceAndDelete() {
    UnicodeSetSpanner m;
    m = new UnicodeSetSpanner(new UnicodeSet("[._]"));
    assertEquals("", "abc", m.deleteFrom("_._a_._b_._c_._"));
    assertEquals("", "_.__.__.__._", m.deleteFrom("_._a_._b_._c_._", SpanCondition.NOT_CONTAINED));
    assertEquals("", "a_._b_._c", m.trim("_._a_._b_._c_._"));
    assertEquals("", "a_._b_._c_._", m.trim("_._a_._b_._c_._", TrimOption.LEADING));
    assertEquals("", "_._a_._b_._c", m.trim("_._a_._b_._c_._", TrimOption.TRAILING));
    assertEquals("", "a??b??c", m.replaceFrom("a_._b_._c", "??", CountMethod.WHOLE_SPAN));
    assertEquals("", "a??b??c", m.replaceFrom(m.trim("_._a_._b_._c_._"), "??", CountMethod.WHOLE_SPAN));
    assertEquals("", "XYXYXYaXYXYXYbXYXYXYcXYXYXY", m.replaceFrom("_._a_._b_._c_._", "XY"));
    assertEquals("", "XYaXYbXYcXY", m.replaceFrom("_._a_._b_._c_._", "XY", CountMethod.WHOLE_SPAN));
    m = new UnicodeSetSpanner(new UnicodeSet("\\p{uppercase}"));
    assertEquals("", "TQBF", m.deleteFrom("The Quick Brown Fox.", SpanCondition.NOT_CONTAINED));
    m = new UnicodeSetSpanner(m.getUnicodeSet().addAll(new UnicodeSet("\\p{lowercase}")));
    assertEquals("", "TheQuickBrownFox", m.deleteFrom("The Quick Brown Fox.", SpanCondition.NOT_CONTAINED));
    m = new UnicodeSetSpanner(new UnicodeSet("[{ab}]"));
    assertEquals("", "XXc acb", m.replaceFrom("ababc acb", "X"));
    assertEquals("", "Xc acb", m.replaceFrom("ababc acb", "X", CountMethod.WHOLE_SPAN));
    assertEquals("", "ababX", m.replaceFrom("ababc acb", "X", CountMethod.WHOLE_SPAN, SpanCondition.NOT_CONTAINED));
}
Also used : UnicodeSetSpanner(android.icu.text.UnicodeSetSpanner) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

UnicodeSet (android.icu.text.UnicodeSet)3 UnicodeSetSpanner (android.icu.text.UnicodeSetSpanner)3 Test (org.junit.Test)2