Search in sources :

Example 31 with UnicodeSetIterator

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

the class UnicodeSetTest method TestIteration.

@Test
public void TestIteration() {
    UnicodeSet us1 = new UnicodeSet("[abcM{xy}]");
    assertEquals("", "M, a-c", CollectionUtilities.join(us1.ranges(), ", "));
    // Sample code
    for (@SuppressWarnings("unused") EntryRange range : us1.ranges()) {
    // do something with code points between range.codepointEnd and range.codepointEnd;
    }
    for (@SuppressWarnings("unused") String s : us1.strings()) {
    // do something with each string;
    }
    String[] tests = { "[M-Qzab{XY}{ZW}]", "[]", "[a]", "[a-c]", "[{XY}]" };
    for (String test : tests) {
        UnicodeSet us = new UnicodeSet(test);
        UnicodeSetIterator it = new UnicodeSetIterator(us);
        for (EntryRange range : us.ranges()) {
            final String title = range.toString();
            logln(title);
            it.nextRange();
            assertEquals(title, it.codepoint, range.codepoint);
            assertEquals(title, it.codepointEnd, range.codepointEnd);
        }
        for (String s : us.strings()) {
            it.nextRange();
            assertEquals("strings", it.string, s);
        }
        assertFalse("", it.next());
    }
}
Also used : UnicodeSetIterator(android.icu.text.UnicodeSetIterator) EntryRange(android.icu.text.UnicodeSet.EntryRange) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

UnicodeSetIterator (android.icu.text.UnicodeSetIterator)31 UnicodeSet (android.icu.text.UnicodeSet)25 Test (org.junit.Test)17 ULocale (android.icu.util.ULocale)6 Transliterator (android.icu.text.Transliterator)5 HashSet (java.util.HashSet)4 RuleBasedCollator (android.icu.text.RuleBasedCollator)3 CollationData (android.icu.impl.coll.CollationData)2 CollationKey (android.icu.text.CollationKey)2 FilteredNormalizer2 (android.icu.text.FilteredNormalizer2)2 Normalizer2 (android.icu.text.Normalizer2)2 RawCollationKey (android.icu.text.RawCollationKey)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 TreeSet (java.util.TreeSet)2 Normalizer2Impl (android.icu.impl.Normalizer2Impl)1