Search in sources :

Example 1 with UTF16CollationIterator

use of android.icu.impl.coll.UTF16CollationIterator in project j2objc by google.

the class CollationElementIterator method setText.

/**
 * Set a new source string for iteration, and reset the offset
 * to the beginning of the text.
 *
 * @param source the new source string for iteration.
 */
public void setText(String source) {
    // TODO: do we need to remember the source string in a field?
    string_ = source;
    CollationIterator newIter;
    boolean numeric = rbc_.settings.readOnly().isNumeric();
    if (rbc_.settings.readOnly().dontCheckFCD()) {
        newIter = new UTF16CollationIterator(rbc_.data, numeric, string_, 0);
    } else {
        newIter = new FCDUTF16CollationIterator(rbc_.data, numeric, string_, 0);
    }
    iter_ = newIter;
    otherHalf_ = 0;
    dir_ = 0;
}
Also used : FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) UTF16CollationIterator(android.icu.impl.coll.UTF16CollationIterator) FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) UTF16CollationIterator(android.icu.impl.coll.UTF16CollationIterator) CollationIterator(android.icu.impl.coll.CollationIterator) FCDIterCollationIterator(android.icu.impl.coll.FCDIterCollationIterator) FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) IterCollationIterator(android.icu.impl.coll.IterCollationIterator)

Example 2 with UTF16CollationIterator

use of android.icu.impl.coll.UTF16CollationIterator in project j2objc by google.

the class RuleBasedCollator method setVariableTop.

/**
 * <strong>[icu]</strong> Sets the variable top to the primary weight of the specified string.
 *
 * <p>Beginning with ICU 53, the variable top is pinned to
 * the top of one of the supported reordering groups,
 * and it must not be beyond the last of those groups.
 * See {@link #setMaxVariable(int)}.
 *
 * @param varTop
 *            one or more (if contraction) characters to which the variable top should be set
 * @return variable top primary weight
 * @exception IllegalArgumentException
 *                is thrown if varTop argument is not a valid variable top element. A variable top element is
 *                invalid when
 *                <ul>
 *                <li>it is a contraction that does not exist in the Collation order
 *                <li>the variable top is beyond
 *                    the last reordering group supported by setMaxVariable()
 *                <li>when the varTop argument is null or zero in length.
 *                </ul>
 * @see #getVariableTop
 * @see RuleBasedCollator#setAlternateHandlingShifted
 * @deprecated ICU 53 Call {@link #setMaxVariable(int)} instead.
 * @hide original deprecated declaration
 */
@Override
@Deprecated
public int setVariableTop(String varTop) {
    checkNotFrozen();
    if (varTop == null || varTop.length() == 0) {
        throw new IllegalArgumentException("Variable top argument string can not be null or zero in length.");
    }
    boolean numeric = settings.readOnly().isNumeric();
    long ce1, ce2;
    if (settings.readOnly().dontCheckFCD()) {
        UTF16CollationIterator ci = new UTF16CollationIterator(data, numeric, varTop, 0);
        ce1 = ci.nextCE();
        ce2 = ci.nextCE();
    } else {
        FCDUTF16CollationIterator ci = new FCDUTF16CollationIterator(data, numeric, varTop, 0);
        ce1 = ci.nextCE();
        ce2 = ci.nextCE();
    }
    if (ce1 == Collation.NO_CE || ce2 != Collation.NO_CE) {
        throw new IllegalArgumentException("Variable top argument string must map to exactly one collation element");
    }
    internalSetVariableTop(ce1 >>> 32);
    return (int) settings.readOnly().variableTop;
}
Also used : FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) UTF16CollationIterator(android.icu.impl.coll.UTF16CollationIterator)

Example 3 with UTF16CollationIterator

use of android.icu.impl.coll.UTF16CollationIterator in project j2objc by google.

the class CollationTest method TestSubSequence.

// ICU4C: TestNulTerminated / renamed for ICU4J
@Test
public void TestSubSequence() {
    CollationData data = CollationRoot.getData();
    // { 0x61, 0x62, 0x61, 0x62 }
    final String s = "abab";
    UTF16CollationIterator ci1 = new UTF16CollationIterator(data, false, s, 0);
    UTF16CollationIterator ci2 = new UTF16CollationIterator(data, false, s, 2);
    for (int i = 0; i < 2; ++i) {
        long ce1 = ci1.nextCE();
        long ce2 = ci2.nextCE();
        if (ce1 != ce2) {
            errln("CollationIterator.nextCE(with start position at 0) != " + "nextCE(with start position at 2) at CE " + i);
        }
    }
}
Also used : FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) UTF16CollationIterator(android.icu.impl.coll.UTF16CollationIterator) CollationData(android.icu.impl.coll.CollationData) Test(org.junit.Test)

Example 4 with UTF16CollationIterator

use of android.icu.impl.coll.UTF16CollationIterator in project j2objc by google.

the class CollationTest method TestImplicits.

@Test
public void TestImplicits() {
    CollationData cd = CollationRoot.getData();
    // Implicit primary weights should be assigned for the following sets,
    // and sort in ascending order by set and then code point.
    // See http://www.unicode.org/reports/tr10/#Implicit_Weights
    // core Han Unified Ideographs
    UnicodeSet coreHan = new UnicodeSet("[\\p{unified_ideograph}&" + "[\\p{Block=CJK_Unified_Ideographs}" + "\\p{Block=CJK_Compatibility_Ideographs}]]");
    // all other Unified Han ideographs
    UnicodeSet otherHan = new UnicodeSet("[\\p{unified ideograph}-" + "[\\p{Block=CJK_Unified_Ideographs}" + "\\p{Block=CJK_Compatibility_Ideographs}]]");
    UnicodeSet unassigned = new UnicodeSet("[[:Cn:][:Cs:][:Co:]]");
    // These have special CLDR root mappings.
    unassigned.remove(0xfffe, 0xffff);
    // Starting with CLDR 26/ICU 54, the root Han order may instead be
    // the Unihan radical-stroke order.
    // The tests should pass either way, so we only test the order of a small set of Han characters
    // whose radical-stroke order is the same as their code point order.
    UnicodeSet someHanInCPOrder = new UnicodeSet("[\\u4E00-\\u4E16\\u4E18-\\u4E2B\\u4E2D-\\u4E3C\\u4E3E-\\u4E48" + "\\u4E4A-\\u4E60\\u4E63-\\u4E8F\\u4E91-\\u4F63\\u4F65-\\u50F1\\u50F3-\\u50F6]");
    UnicodeSet inOrder = new UnicodeSet(someHanInCPOrder);
    inOrder.addAll(unassigned).freeze();
    UnicodeSet[] sets = { coreHan, otherHan, unassigned };
    int prev = 0;
    long prevPrimary = 0;
    UTF16CollationIterator ci = new UTF16CollationIterator(cd, false, "", 0);
    for (int i = 0; i < sets.length; ++i) {
        UnicodeSetIterator iter = new UnicodeSetIterator(sets[i]);
        while (iter.next()) {
            String s = iter.getString();
            int c = s.codePointAt(0);
            ci.setText(false, s, 0);
            long ce = ci.nextCE();
            long ce2 = ci.nextCE();
            if (ce == Collation.NO_CE || ce2 != Collation.NO_CE) {
                errln("CollationIterator.nextCE(0x" + Utility.hex(c) + ") did not yield exactly one CE");
                continue;
            }
            if ((ce & 0xffffffffL) != Collation.COMMON_SEC_AND_TER_CE) {
                errln("CollationIterator.nextCE(U+" + Utility.hex(c, 4) + ") has non-common sec/ter weights: 0x" + Utility.hex(ce & 0xffffffffL, 8));
                continue;
            }
            long primary = ce >>> 32;
            if (!(primary > prevPrimary) && inOrder.contains(c) && inOrder.contains(prev)) {
                errln("CE(U+" + Utility.hex(c) + ")=0x" + Utility.hex(primary) + ".. not greater than CE(U+" + Utility.hex(prev) + ")=0x" + Utility.hex(prevPrimary) + "..");
            }
            prev = c;
            prevPrimary = primary;
        }
    }
}
Also used : UnicodeSetIterator(android.icu.text.UnicodeSetIterator) FCDUTF16CollationIterator(android.icu.impl.coll.FCDUTF16CollationIterator) UTF16CollationIterator(android.icu.impl.coll.UTF16CollationIterator) CollationData(android.icu.impl.coll.CollationData) UnicodeSet(android.icu.text.UnicodeSet) Test(org.junit.Test)

Aggregations

FCDUTF16CollationIterator (android.icu.impl.coll.FCDUTF16CollationIterator)4 UTF16CollationIterator (android.icu.impl.coll.UTF16CollationIterator)4 CollationData (android.icu.impl.coll.CollationData)2 Test (org.junit.Test)2 CollationIterator (android.icu.impl.coll.CollationIterator)1 FCDIterCollationIterator (android.icu.impl.coll.FCDIterCollationIterator)1 IterCollationIterator (android.icu.impl.coll.IterCollationIterator)1 UnicodeSet (android.icu.text.UnicodeSet)1 UnicodeSetIterator (android.icu.text.UnicodeSetIterator)1