Search in sources :

Example 26 with UnicodeSet

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

the class UtilityTest method TestUnicodeSet.

@Test
public void TestUnicodeSet() {
    String[] array = new String[] { "a", "b", "c", "{de}" };
    List list = Arrays.asList(array);
    Set aset = new HashSet(list);
    logln(" *** The source set's size is: " + aset.size());
    // The size reads 4
    UnicodeSet set = new UnicodeSet();
    set.clear();
    set.addAll(aset);
    logln(" *** After addAll, the UnicodeSet size is: " + set.size());
// The size should also read 4, but 0 is seen instead
}
Also used : HashSet(java.util.HashSet) UnicodeSet(android.icu.text.UnicodeSet) Set(java.util.Set) List(java.util.List) CaseInsensitiveString(android.icu.util.CaseInsensitiveString) UnicodeSet(android.icu.text.UnicodeSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 27 with UnicodeSet

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

the class CollationDataBuilder method setDigitTags.

protected void setDigitTags() {
    UnicodeSet digits = new UnicodeSet("[:Nd:]");
    UnicodeSetIterator iter = new UnicodeSetIterator(digits);
    while (iter.next()) {
        assert (iter.codepoint != UnicodeSetIterator.IS_STRING);
        int c = iter.codepoint;
        int ce32 = trie.get(c);
        if (ce32 != Collation.FALLBACK_CE32 && ce32 != Collation.UNASSIGNED_CE32) {
            int index = addCE32(ce32);
            if (index > Collation.MAX_INDEX) {
                throw new IndexOutOfBoundsException("too many mappings");
            // BufferOverflowException is a better fit
            // but cannot be constructed with a message string.
            }
            ce32 = Collation.makeCE32FromTagIndexAndLength(Collation.DIGIT_TAG, index, // u_charDigitValue(c)
            UCharacter.digit(c));
            trie.set(c, ce32);
        }
    }
}
Also used : UnicodeSetIterator(android.icu.text.UnicodeSetIterator) UnicodeSet(android.icu.text.UnicodeSet)

Example 28 with UnicodeSet

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

the class TestBoilerplate method getSet.

public static <T> UnicodeSet getSet(Map<Integer, T> m, T value) {
    UnicodeSet result = new UnicodeSet();
    for (Iterator<Integer> it = m.keySet().iterator(); it.hasNext(); ) {
        Integer key = it.next();
        T val = m.get(key);
        if (!val.equals(value))
            continue;
        result.add(key.intValue());
    }
    return result;
}
Also used : UnicodeSet(android.icu.text.UnicodeSet)

Example 29 with UnicodeSet

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

the class StringTokenizer method nextToken.

/**
 * Returns the next token in this string tokenizer's string. First,
 * the set of characters considered to be delimiters by this
 * <tt>StringTokenizer</tt> object is changed to be the characters in
 * the string <tt>delim</tt>. Then the next token in the string
 * after the current position is returned. The current position is
 * advanced beyond the recognized token.  The new delimiter set
 * remains the default after this call.
 * @param delim the new delimiters.
 * @return the next token, after switching to the new delimiter set.
 * @exception NoSuchElementException if there are no more tokens in
 *            this tokenizer's string.
 */
public String nextToken(String delim) {
    m_delimiters_ = EMPTY_DELIMITER_;
    if (delim != null && delim.length() > 0) {
        m_delimiters_ = new UnicodeSet();
        m_delimiters_.addAll(delim);
    }
    return nextToken(m_delimiters_);
}
Also used : UnicodeSet(android.icu.text.UnicodeSet)

Example 30 with UnicodeSet

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

the class BasicTest method TestCanonIterData.

@Test
public void TestCanonIterData() {
    // For now, just a regression test.
    Normalizer2Impl impl = Norm2AllModes.getNFCInstance().impl.ensureCanonIterData();
    // but it is not a segment starter because it occurs in a decomposition mapping.
    if (impl.isCanonSegmentStarter(0xfb5)) {
        errln("isCanonSegmentStarter(U+0fb5)=true is wrong");
    }
    // For [:Segment_Starter:] to work right, not just the property function has to work right,
    // UnicodeSet also needs a correct range starts set.
    UnicodeSet segStarters = new UnicodeSet("[:Segment_Starter:]").freeze();
    if (segStarters.contains(0xfb5)) {
        errln("[:Segment_Starter:].contains(U+0fb5)=true is wrong");
    }
    // Try characters up to Kana and miscellaneous CJK but below Han (for expediency).
    for (int c = 0; c <= 0x33ff; ++c) {
        boolean isStarter = impl.isCanonSegmentStarter(c);
        boolean isContained = segStarters.contains(c);
        if (isStarter != isContained) {
            errln(String.format("discrepancy: isCanonSegmentStarter(U+%04x)=%5b != " + "[:Segment_Starter:].contains(same)", c, isStarter));
        }
    }
}
Also used : Normalizer2Impl(android.icu.impl.Normalizer2Impl) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

UnicodeSet (android.icu.text.UnicodeSet)158 Test (org.junit.Test)112 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)25 Transliterator (android.icu.text.Transliterator)19 ReplaceableString (android.icu.text.ReplaceableString)14 ULocale (android.icu.util.ULocale)13 CaseInsensitiveString (android.icu.util.CaseInsensitiveString)9 Normalizer2 (android.icu.text.Normalizer2)7 RuleBasedCollator (android.icu.text.RuleBasedCollator)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 FilteredNormalizer2 (android.icu.text.FilteredNormalizer2)4 SpoofChecker (android.icu.text.SpoofChecker)4 TreeSet (java.util.TreeSet)4 UnicodeMap (android.icu.dev.util.UnicodeMap)3 AlphabeticIndex (android.icu.text.AlphabeticIndex)3 CollationKey (android.icu.text.CollationKey)3 RawCollationKey (android.icu.text.RawCollationKey)3 CheckResult (android.icu.text.SpoofChecker.CheckResult)3 SpanCondition (android.icu.text.UnicodeSet.SpanCondition)3