Search in sources :

Example 16 with CollationSettings

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

the class RuleBasedCollator method setFrenchCollation.

/**
 * Sets the mode for the direction of SECONDARY weights to be used in French collation. The default value is false,
 * which treats SECONDARY weights in the order they appear. If set to true, the SECONDARY weights will be sorted
 * backwards. See the section on <a href="http://userguide.icu-project.org/collation/architecture">
 * French collation</a> for more information.
 *
 * @param flag
 *            true to set the French collation on, false to set it off
 * @see #isFrenchCollation
 * @see #setFrenchCollationDefault
 */
public void setFrenchCollation(boolean flag) {
    checkNotFrozen();
    if (flag == isFrenchCollation()) {
        return;
    }
    CollationSettings ownedSettings = getOwnedSettings();
    ownedSettings.setFlag(CollationSettings.BACKWARD_SECONDARY, flag);
    setFastLatinOptions(ownedSettings);
}
Also used : CollationSettings(android.icu.impl.coll.CollationSettings)

Example 17 with CollationSettings

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

the class RuleBasedCollator method doCompare.

/**
 * Compares two CharSequences.
 * @deprecated This API is ICU internal only.
 * @hide original deprecated declaration
 * @hide draft / provisional / internal are hidden on Android
 */
@Override
@Deprecated
protected int doCompare(CharSequence left, CharSequence right) {
    if (left == right) {
        return Collation.EQUAL;
    }
    // Identical-prefix test.
    int equalPrefixLength = 0;
    for (; ; ) {
        if (equalPrefixLength == left.length()) {
            if (equalPrefixLength == right.length()) {
                return Collation.EQUAL;
            }
            break;
        } else if (equalPrefixLength == right.length() || left.charAt(equalPrefixLength) != right.charAt(equalPrefixLength)) {
            break;
        }
        ++equalPrefixLength;
    }
    CollationSettings roSettings = settings.readOnly();
    boolean numeric = roSettings.isNumeric();
    if (equalPrefixLength > 0) {
        if ((equalPrefixLength != left.length() && data.isUnsafeBackward(left.charAt(equalPrefixLength), numeric)) || (equalPrefixLength != right.length() && data.isUnsafeBackward(right.charAt(equalPrefixLength), numeric))) {
            // Identical prefix: Back up to the start of a contraction or reordering sequence.
            while (--equalPrefixLength > 0 && data.isUnsafeBackward(left.charAt(equalPrefixLength), numeric)) {
            }
        }
    // Notes:
    // - A longer string can compare equal to a prefix of it if only ignorables follow.
    // - With a backward level, a longer string can compare less-than a prefix of it.
    // Pass the actual start of each string into the CollationIterators,
    // plus the equalPrefixLength position,
    // so that prefix matches back into the equal prefix work.
    }
    int result;
    int fastLatinOptions = roSettings.fastLatinOptions;
    if (fastLatinOptions >= 0 && (equalPrefixLength == left.length() || left.charAt(equalPrefixLength) <= CollationFastLatin.LATIN_MAX) && (equalPrefixLength == right.length() || right.charAt(equalPrefixLength) <= CollationFastLatin.LATIN_MAX)) {
        result = CollationFastLatin.compareUTF16(data.fastLatinTable, roSettings.fastLatinPrimaries, fastLatinOptions, left, right, equalPrefixLength);
    } else {
        result = CollationFastLatin.BAIL_OUT_RESULT;
    }
    if (result == CollationFastLatin.BAIL_OUT_RESULT) {
        CollationBuffer buffer = null;
        try {
            buffer = getCollationBuffer();
            if (roSettings.dontCheckFCD()) {
                buffer.leftUTF16CollIter.setText(numeric, left, equalPrefixLength);
                buffer.rightUTF16CollIter.setText(numeric, right, equalPrefixLength);
                result = CollationCompare.compareUpToQuaternary(buffer.leftUTF16CollIter, buffer.rightUTF16CollIter, roSettings);
            } else {
                buffer.leftFCDUTF16Iter.setText(numeric, left, equalPrefixLength);
                buffer.rightFCDUTF16Iter.setText(numeric, right, equalPrefixLength);
                result = CollationCompare.compareUpToQuaternary(buffer.leftFCDUTF16Iter, buffer.rightFCDUTF16Iter, roSettings);
            }
        } finally {
            releaseCollationBuffer(buffer);
        }
    }
    if (result != Collation.EQUAL || roSettings.getStrength() < Collator.IDENTICAL) {
        return result;
    }
    CollationBuffer buffer = null;
    try {
        buffer = getCollationBuffer();
        // Compare identical level.
        Normalizer2Impl nfcImpl = data.nfcImpl;
        if (roSettings.dontCheckFCD()) {
            buffer.leftUTF16NFDIter.setText(left, equalPrefixLength);
            buffer.rightUTF16NFDIter.setText(right, equalPrefixLength);
            return compareNFDIter(nfcImpl, buffer.leftUTF16NFDIter, buffer.rightUTF16NFDIter);
        } else {
            buffer.leftFCDUTF16NFDIter.setText(nfcImpl, left, equalPrefixLength);
            buffer.rightFCDUTF16NFDIter.setText(nfcImpl, right, equalPrefixLength);
            return compareNFDIter(nfcImpl, buffer.leftFCDUTF16NFDIter, buffer.rightFCDUTF16NFDIter);
        }
    } finally {
        releaseCollationBuffer(buffer);
    }
}
Also used : CollationSettings(android.icu.impl.coll.CollationSettings) Normalizer2Impl(android.icu.impl.Normalizer2Impl)

Example 18 with CollationSettings

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

the class RuleBasedCollator method setLowerCaseFirst.

/**
 * Sets the orders of lower cased characters to sort before upper cased characters, in strength TERTIARY. The
 * default mode is false. If true is set, the RuleBasedCollator will sort lower cased characters before the upper
 * cased ones. Otherwise, if false is set, the RuleBasedCollator will ignore case preferences.
 *
 * @param lowerfirst
 *            true for sorting lower cased characters before upper cased characters, false to ignore case
 *            preferences.
 * @see #isLowerCaseFirst
 * @see #isUpperCaseFirst
 * @see #setUpperCaseFirst
 * @see #setCaseFirstDefault
 */
public void setLowerCaseFirst(boolean lowerfirst) {
    checkNotFrozen();
    if (lowerfirst == isLowerCaseFirst()) {
        return;
    }
    CollationSettings ownedSettings = getOwnedSettings();
    ownedSettings.setCaseFirst(lowerfirst ? CollationSettings.CASE_FIRST : 0);
    setFastLatinOptions(ownedSettings);
}
Also used : CollationSettings(android.icu.impl.coll.CollationSettings)

Example 19 with CollationSettings

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

the class RuleBasedCollator method internalSetVariableTop.

private void internalSetVariableTop(long varTop) {
    if (varTop != settings.readOnly().variableTop) {
        // Pin the variable top to the end of the reordering group which contains it.
        // Only a few special groups are supported.
        int group = data.getGroupForPrimary(varTop);
        if (group < Collator.ReorderCodes.FIRST || Collator.ReorderCodes.CURRENCY < group) {
            throw new IllegalArgumentException("The variable top must be a primary weight in " + "the space/punctuation/symbols/currency symbols range");
        }
        long v = data.getLastPrimaryForGroup(group);
        assert (v != 0 && v >= varTop);
        varTop = v;
        if (varTop != settings.readOnly().variableTop) {
            CollationSettings ownedSettings = getOwnedSettings();
            ownedSettings.setMaxVariable(group - Collator.ReorderCodes.FIRST, getDefaultSettings().options);
            ownedSettings.variableTop = varTop;
            setFastLatinOptions(ownedSettings);
        }
    }
}
Also used : CollationSettings(android.icu.impl.coll.CollationSettings)

Aggregations

CollationSettings (android.icu.impl.coll.CollationSettings)19 Normalizer2Impl (android.icu.impl.Normalizer2Impl)1