Java Code Examples for android.icu.lang.UCharacter#hasBinaryProperty()

The following examples show how to use android.icu.lang.UCharacter#hasBinaryProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Emoji.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the given code point is emoji modifier base.
 * @param c codepoint to check
 * @return true if is emoji modifier base
 */
public static boolean isEmojiModifierBase(int c) {
    // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to
    // keep them as emoji modifier bases since there are fonts and user-generated text out there
    // that treats these as potential emoji bases.
    if (c == 0x1F91D || c == 0x1F93C) {
        return true;
    }
    // Emoji Modifier Base characters new in Unicode emoji 11
    // From https://www.unicode.org/Public/emoji/11.0/emoji-data.txt
    // TODO: Remove once emoji-data.text 11 is in ICU or update to 11.
    if ((0x1F9B5 <= c && c <= 0x1F9B6) || (0x1F9B8 <= c && c <= 0x1F9B9)) {
        return true;
    }
    return UCharacter.hasBinaryProperty(c, UProperty.EMOJI_MODIFIER_BASE);
}
 
Example 2
Source File: DigitsKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@NonNull
private static String stripBidiControls(@NonNull String sign) {
    // For the sake of simplicity, we operate on code units, since all bidi controls are
    // in the BMP. We also expect the string to be very short (almost always 1 character), so we
    // don't need to use StringBuilder.
    String result = "";
    for (int i = 0; i < sign.length(); i++) {
        final char c = sign.charAt(i);
        if (!UCharacter.hasBinaryProperty(c, UProperty.BIDI_CONTROL)) {
            if (result.isEmpty()) {
                result = String.valueOf(c);
            } else {
                // This should happen very rarely, only if we have a multi-character sign,
                // or a sign outside BMP.
                result += c;
            }
        }
    }
    return result;
}
 
Example 3
Source File: RoundTripTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public boolean is(String sourceString) {
    if (sourceString.length() == 0) return true;
    char ch = sourceString.charAt(sourceString.length() - 1); // don't worry about surrogates.
    if (UCharacter.hasBinaryProperty(ch, UProperty.LOGICAL_ORDER_EXCEPTION)) return false;


    // disallow anything with a wordbreak between
    /*
    if (UTF16.countCodePoint(sourceString) <= 1) return true;
    thaiBreak.setText(sourceString);
    for (int pos = thaiBreak.first(); pos != BreakIterator.DONE; pos = thaiBreak.next()) {
        if (pos > 0 && pos < sourceString.length()) {
            System.out.println("Skipping " + Utility.escape(sourceString));
            return false;
        }
    }
     */
    return true;
}
 
Example 4
Source File: TestDeprecatedNormalizerAPI.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestRoundTrip() {
    int options = Normalizer.IGNORE_HANGUL;
    boolean compat = false;

    ComposedCharIter iter = new ComposedCharIter(false, options);
    while (iter.hasNext()) {
        final char ch = iter.next();

        String chStr = String.valueOf(ch);
        String decomp = iter.decomposition();
        String comp = Normalizer.compose(decomp, compat);

        if (UCharacter.hasBinaryProperty(ch, UProperty.FULL_COMPOSITION_EXCLUSION)) {
            logln("Skipped excluded char " + hex(ch) + " (" + UCharacter.getName(ch) + ")" );
            continue;
        }

        // Avoid disparaged characters
        if (decomp.length() == 4) continue;

        if (!comp.equals(chStr)) {
            errln("ERROR: Round trip invalid: " + hex(chStr) + " --> " + hex(decomp)
                + " --> " + hex(comp));

            errln("  char decomp is '" + decomp + "'");
        }
    }
}
 
Example 5
Source File: UCharacterCaseTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestTitleRegression() throws java.io.IOException {
    boolean isIgnorable = UCharacter.hasBinaryProperty('\'', UProperty.CASE_IGNORABLE);
    assertTrue("Case Ignorable check of ASCII apostrophe", isIgnorable);
    assertEquals("Titlecase check",
            "The Quick Brown Fox Can't Jump Over The Lazy Dogs.",
            UCharacter.toTitleCase(ULocale.ENGLISH, "THE QUICK BROWN FOX CAN'T JUMP OVER THE LAZY DOGS.", null));
}
 
Example 6
Source File: Emoji.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the given code point is emoji modifier.
 */
public static boolean isEmojiModifier(int codePoint) {
    return UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI_MODIFIER);
}
 
Example 7
Source File: Emoji.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Returns true if the character has Emoji property.
 */
public static boolean isEmoji(int codePoint) {
    return isNewEmoji(codePoint) || UCharacter.hasBinaryProperty(codePoint, UProperty.EMOJI);
}
 
Example 8
Source File: BaseKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private static boolean isVariationSelector(int codepoint) {
    return UCharacter.hasBinaryProperty(codepoint, UProperty.VARIATION_SELECTOR);
}