android.icu.lang.UCharacter Java Examples

The following examples show how to use android.icu.lang.UCharacter. 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: UCharacterSurrogateTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void TestToCodePoint() {
    final char[] pairs = {(char) (UCharacter.MIN_HIGH_SURROGATE + 0),
            (char) (UCharacter.MIN_LOW_SURROGATE + 0),
            (char) (UCharacter.MIN_HIGH_SURROGATE + 1),
            (char) (UCharacter.MIN_LOW_SURROGATE + 1),
            (char) (UCharacter.MIN_HIGH_SURROGATE + 2),
            (char) (UCharacter.MIN_LOW_SURROGATE + 2),
            (char) (UCharacter.MAX_HIGH_SURROGATE - 2),
            (char) (UCharacter.MAX_LOW_SURROGATE - 2),
            (char) (UCharacter.MAX_HIGH_SURROGATE - 1),
            (char) (UCharacter.MAX_LOW_SURROGATE - 1),
            (char) (UCharacter.MAX_HIGH_SURROGATE - 0),
            (char) (UCharacter.MAX_LOW_SURROGATE - 0),};
    for (int i = 0; i < pairs.length; i += 2) {
        int cp = UCharacter.toCodePoint(pairs[i], pairs[i + 1]);
        if (pairs[i] != UTF16.getLeadSurrogate(cp)
                || pairs[i + 1] != UTF16.getTrailSurrogate(cp)) {

            errln(Integer.toHexString(pairs[i]) + ", " + pairs[i + 1]);
            break;
        }
    }
}
 
Example #2
Source File: UCharacterName.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Gets the character extended type
* @param ch character to be tested
* @return extended type it is associated with
*/
private static int getType(int ch)
{
    if (UCharacterUtility.isNonCharacter(ch)) {
        // not a character we return a invalid category count
        return NON_CHARACTER_;
    }
    int result = UCharacter.getType(ch);
    if (result == UCharacterCategory.SURROGATE) {
        if (ch <= UTF16.LEAD_SURROGATE_MAX_VALUE) {
            result = LEAD_SURROGATE_;
        }
        else {
            result = TRAIL_SURROGATE_;
        }
    }
    return result;
}
 
Example #3
Source File: TransliteratorParser.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Implement SymbolTable API.  Parse out a symbol reference
 * name.
 */
@Override
public String parseReference(String text, ParsePosition pos, int limit) {
    int start = pos.getIndex();
    int i = start;
    while (i < limit) {
        char c = text.charAt(i);
        if ((i==start && !UCharacter.isUnicodeIdentifierStart(c)) ||
            !UCharacter.isUnicodeIdentifierPart(c)) {
            break;
        }
        ++i;
    }
    if (i == start) { // No valid name chars
        return null;
    }
    pos.setIndex(i);
    return text.substring(start, i);
}
 
Example #4
Source File: TestBidiTransform.java    From j2objc with Apache License 2.0 6 votes vote down vote up
private static String pseudoScript(String text) {
    char[] uchars = text.toCharArray();
    for (int i = uchars.length; i-- > 0;) {
        char uch = uchars[i];
        switch (UCharacter.getDirectionality(uch)) {
            case UCharacter.RIGHT_TO_LEFT:
                uchars[i] = substituteChar(uch, MIN_HEB_LETTER, 'K', 'Z');
                break;
            case UCharacter.RIGHT_TO_LEFT_ARABIC:
                if (uch > 0xFE00) {
                    uchars[i] = substituteChar(uch, MIN_SHAPED_LETTER, 'F', 'J');
                } else {
                    uchars[i] = substituteChar(uch, MIN_ARAB_LETTER, 'A', 'E');
                }
                break;
            case UCharacter.ARABIC_NUMBER:
                uchars[i] = substituteChar(uch, ARAB_ZERO, '5', '9');
                break;
            default:
                break;
        }
    }
    return new String(uchars);
}
 
Example #5
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 #6
Source File: UCharacterSurrogateTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void TestIsSurrogatePair() {
    if (UCharacter.isSurrogatePair(
            (char) (UCharacter.MIN_HIGH_SURROGATE - 1),
            UCharacter.MIN_LOW_SURROGATE))
        errln("0xd7ff,0xdc00");
    if (UCharacter.isSurrogatePair(
            (char) (UCharacter.MAX_HIGH_SURROGATE + 1),
            UCharacter.MIN_LOW_SURROGATE))
        errln("0xd800,0xdc00");
    if (UCharacter.isSurrogatePair(UCharacter.MIN_HIGH_SURROGATE,
            (char) (UCharacter.MIN_LOW_SURROGATE - 1)))
        errln("0xd800,0xdbff");
    if (UCharacter.isSurrogatePair(UCharacter.MIN_HIGH_SURROGATE,
            (char) (UCharacter.MAX_LOW_SURROGATE + 1)))
        errln("0xd800,0xe000");
    if (!UCharacter.isSurrogatePair(UCharacter.MIN_HIGH_SURROGATE,
            UCharacter.MIN_LOW_SURROGATE))
        errln("0xd800,0xdc00");
}
 
Example #7
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestToTitleCaseCoverage(){
    //Calls the function "toTitleCase(Locale locale, String str, BreakIterator breakiter)"
    String[] locale={"en","fr","zh","ko","ja","it","de",""};
    for(int i=0; i<locale.length; i++){
        UCharacter.toTitleCase(new Locale(locale[i]), "", null);
    }

    // Calls the function "String toTitleCase(ULocale locale, String str, BreakIterator titleIter, int options)"
    // Tests when "if (locale == null)" is true
    UCharacter.toTitleCase((ULocale)null, "", null, 0);

    // TODO: Tests when "if(index==BreakIterator.DONE || index>srcLength)" is true
    // TODO: Tests when "while((c=iter.nextCaseMapCP())>=0 && UCaseProps.NONE==gCsp.getType(c))" is false
    // TODO: Tests when "if(prev<titleStart)" is false
    // TODO: Tests when "if(c<=0xffff)" is false
    // TODO: Tests when "if(c<=0xffff)" is false
    // TODO: Tests when "if(titleLimit<index)" is false
    // TODO: Tests when "else if((nc=iter.nextCaseMapCP())>=0)" is false
}
 
Example #8
Source File: UCharacterSurrogateTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void TestToChars() {
    char[] chars = new char[3];
    int cp = UCharacter.toCodePoint(UCharacter.MIN_HIGH_SURROGATE,
            UCharacter.MIN_LOW_SURROGATE);
    UCharacter.toChars(cp, chars, 1);
    if (chars[1] != UCharacter.MIN_HIGH_SURROGATE
            || chars[2] != UCharacter.MIN_LOW_SURROGATE) {

        errln("fail");
    }

    chars = UCharacter.toChars(cp);
    if (chars[0] != UCharacter.MIN_HIGH_SURROGATE
            || chars[1] != UCharacter.MIN_LOW_SURROGATE) {

        errln("fail");
    }
}
 
Example #9
Source File: CollationDataBuilder.java    From j2objc with Apache License 2.0 6 votes vote down vote up
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, UCharacter.digit(c));  // u_charDigitValue(c)
            trie.set(c, ce32);
        }
    }
}
 
Example #10
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestGetIntPropertyMaxValue(){
    /* Testing UCharacter.getIntPropertyMaxValue(type) */
    // Testing when "else if (type < UProperty.INT_START)" is true
    int[] cases = {UProperty.BINARY_LIMIT, UProperty.BINARY_LIMIT+1,
            UProperty.INT_START-2, UProperty.INT_START-1};
    for(int i=0; i<cases.length; i++){
        if(UCharacter.getIntPropertyMaxValue(cases[i]) != -1){
            errln("UCharacter.getIntPropertyMaxValue was suppose to return -1 " +
                    "but got " + UCharacter.getIntPropertyMaxValue(cases[i]));
        }
    }

    // TODO: Testing when the case statment reaches "default"
    // After testing between values of UProperty.INT_START and
    // UProperty.INT_LIMIT are covered, none of the values reaches default.
}
 
Example #11
Source File: TransliteratorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestCasing() {
    Transliterator toLower = Transliterator.getInstance("lower");
    Transliterator toCasefold = Transliterator.getInstance("casefold");
    Transliterator toUpper = Transliterator.getInstance("upper");
    Transliterator toTitle = Transliterator.getInstance("title");
    for (int i = 0; i < 0x600; ++i) {
        String s = UTF16.valueOf(i);

        String lower = UCharacter.toLowerCase(ULocale.ROOT, s);
        assertEquals("Lowercase", lower, toLower.transform(s));

        String casefold = UCharacter.foldCase(s, true);
        assertEquals("Casefold", casefold, toCasefold.transform(s));

        String title = UCharacter.toTitleCase(ULocale.ROOT, s, null);
        assertEquals("Title", title, toTitle.transform(s));

        String upper = UCharacter.toUpperCase(ULocale.ROOT, s);
        assertEquals("Upper", upper, toUpper.transform(s));
    }
}
 
Example #12
Source File: BidiTransform.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Performs character mirroring without reordering. When this method is
 * called, <code>{@link #text}</code> should be in a Logical form.
 */
private void mirror() {
    if ((reorderingOptions & Bidi.DO_MIRRORING) == 0) {
        return;
    }
    StringBuffer sb = new StringBuffer(text);
    byte[] levels = bidi.getLevels();
    for (int i = 0, n = levels.length; i < n;) {
        int ch = UTF16.charAt(sb, i);
        if ((levels[i] & 1) != 0) {
            UTF16.setCharAt(sb, i, UCharacter.getMirror(ch));
        }
        i += UTF16.getCharCount(ch);
    }
    text = sb.toString();
    reorderingOptions &= ~Bidi.DO_MIRRORING;
}
 
Example #13
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Tests for base characters and their cellwidth
*/
@Test
public void TestBase()
{
    int base[] = {0x0061, 0x000031, 0x0003d2};
    int nonbase[] = {0x002B, 0x000020, 0x00203B};
    int size = base.length;
    for (int i = 0; i < size; i ++)
    {
        if (UCharacter.isBaseForm(nonbase[i]))
        {
            errln("FAIL \\u" + hex(nonbase[i]) +
                        " expected not to be a base character");
            break;
        }
        if (!UCharacter.isBaseForm(base[i]))
        {
            errln("FAIL \\u" + hex(base[i]) +
                  " expected to be a base character");
            break;
        }
    }
}
 
Example #14
Source File: AlphabeticIndex.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Return a list of the first character in each script. Only exposed for testing.
 *
 * @return list of first characters in each script
 * @deprecated This API is ICU internal, only for testing.
 * @hide original deprecated declaration
 * @hide draft / provisional / internal are hidden on Android
 */
@Deprecated
public List<String> getFirstCharactersInScripts() {
    List<String> dest = new ArrayList<String>(200);
    // Fetch the script-first-primary contractions which are defined in the root collator.
    // They all start with U+FDD1.
    UnicodeSet set = new UnicodeSet();
    collatorPrimaryOnly.internalAddContractions(0xFDD1, set);
    if (set.isEmpty()) {
        throw new UnsupportedOperationException(
                "AlphabeticIndex requires script-first-primary contractions");
    }
    for (String boundary : set) {
        int gcMask = 1 << UCharacter.getType(boundary.codePointAt(1));
        if ((gcMask & (GC_L_MASK | GC_CN_MASK)) == 0) {
            // Ignore boundaries for the special reordering groups.
            // Take only those for "real scripts" (where the sample character is a Letter,
            // and the one for unassigned implicit weights (Cn).
            continue;
        }
        dest.add(boundary);
    }
    return dest;
}
 
Example #15
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 #16
Source File: IntTrieBuilder.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Get a 32 bit data from the table data
 * @param ch  code point for which data is to be retrieved.
 * @param inBlockZero  Output parameter, inBlockZero[0] returns true if the
 *                      char maps into block zero, otherwise false.
 * @return the 32 bit data value.
 */
public int getValue(int ch, boolean [] inBlockZero) 
{
    // valid, uncompacted trie and valid c?
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE || ch < 0) {
        if (inBlockZero != null) {
            inBlockZero[0] = true;
        }
        return 0;
    }

    int block = m_index_[ch >> SHIFT_];
    if (inBlockZero != null) {
        inBlockZero[0] = (block == 0);
    }
    return m_data_[Math.abs(block) + (ch & MASK_)];
}
 
Example #17
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 #18
Source File: Trie.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Internal trie getter from a code point.
* Could be faster(?) but longer with
*   if((c32)<=0xd7ff) { (result)=_TRIE_GET_RAW(trie, data, 0, c32); }
* Gets the offset to data which the codepoint points to
* @param ch codepoint
* @return offset to data
*/
protected final int getCodePointOffset(int ch)
{
    // if ((ch >> 16) == 0) slower
    if (ch < 0) {
        return -1;
    } else if (ch < UTF16.LEAD_SURROGATE_MIN_VALUE) {
        // fastpath for the part of the BMP below surrogates (D800) where getRawOffset() works
        return getRawOffset(0, (char)ch);
    } else if (ch < UTF16.SUPPLEMENTARY_MIN_VALUE) {
        // BMP codepoint
        return getBMPOffset((char)ch);
    } else if (ch <= UCharacter.MAX_VALUE) {
        // look at the construction of supplementary characters
        // trail forms the ends of it.
        return getSurrogateOffset(UTF16.getLeadSurrogate(ch),
                                  (char)(ch & SURROGATE_MASK_));
    } else {
        // return -1 if there is an error, in this case we return
        return -1;
    }
}
 
Example #19
Source File: SpoofChecker.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the set of numerics for a string, according to UTS 39 section 5.3.
 */
private void getNumerics(String input, UnicodeSet result) {
    result.clear();

    for (int utf16Offset = 0; utf16Offset < input.length();) {
        int codePoint = Character.codePointAt(input, utf16Offset);
        utf16Offset += Character.charCount(codePoint);

        // Store a representative character for each kind of decimal digit
        if (UCharacter.getType(codePoint) == UCharacterCategory.DECIMAL_DIGIT_NUMBER) {
            // Store the zero character as a representative for comparison.
            // Unicode guarantees it is codePoint - value
            result.add(codePoint - UCharacter.getNumericValue(codePoint));
        }
    }
}
 
Example #20
Source File: RoundTripTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public static boolean isCamel(String a) {
    //System.out.println("CamelTest");
    // see if string is of the form aB; e.g. lower, then upper or title
    int cp;
    boolean haveLower = false;
    for (int i = 0; i < a.length(); i += UTF16.getCharCount(cp)) {
        cp = UTF16.charAt(a, i);
        int t = UCharacter.getType(cp);
        //System.out.println("\t" + t + " " + Integer.toString(cp,16) + " " + UCharacter.getName(cp));
        switch (t) {
        case Character.UPPERCASE_LETTER:
            if (haveLower) return true;
            break;
        case Character.TITLECASE_LETTER:
            if (haveLower) return true;
            // drop through, since second letter is lower.
        case Character.LOWERCASE_LETTER:
            haveLower = true;
            break;
        }
    }
    //System.out.println("FALSE");
    return false;
}
 
Example #21
Source File: NormalizationMonkeyTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
String getTestSource() {
if (random == null) {
    random = createRandom(); // use test framework's random seed
}
    String source = "";
    int i = 0;
    while (i < (random.nextInt(maxCharCount) + 1)) {
        int codepoint = random.nextInt(maxCodePoint);
        //Elimate unassigned characters
        while (UCharacter.getType(codepoint) == UCharacterCategory.UNASSIGNED) {
            codepoint = random.nextInt(maxCodePoint);
        }
        source = source + UTF16.valueOf(codepoint);
        i++;
    }
    return source;
}
 
Example #22
Source File: UCharacterSurrogateTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void TestIsSupplementaryCodePoint() {
    if (UCharacter.isSupplementaryCodePoint(-1))
        errln("-1");
    if (UCharacter.isSupplementaryCodePoint(0))
        errln("0");
    if (UCharacter
            .isSupplementaryCodePoint(UCharacter.MIN_SUPPLEMENTARY_CODE_POINT - 1))
        errln("0xffff");
    if (!UCharacter
            .isSupplementaryCodePoint(UCharacter.MIN_SUPPLEMENTARY_CODE_POINT))
        errln("0x10000");
    if (!UCharacter.isSupplementaryCodePoint(UCharacter.MAX_CODE_POINT))
        errln("0x10ffff");
    if (UCharacter.isSupplementaryCodePoint(UCharacter.MAX_CODE_POINT + 1))
        errln("0x110000");
}
 
Example #23
Source File: TransliteratorTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
public void TestSurrogateCasing () {
    // check that casing handles surrogates
    // titlecase is currently defective
    int dee = UTF16.charAt(DESERET_dee,0);
    int DEE = UCharacter.toTitleCase(dee);
    if (!UTF16.valueOf(DEE).equals(DESERET_DEE)) {
        errln("Fails titlecase of surrogates" + Integer.toString(dee,16) + ", " + Integer.toString(DEE,16));
    }

    if (!UCharacter.toUpperCase(DESERET_dee + DESERET_DEE).equals(DESERET_DEE + DESERET_DEE)) {
        errln("Fails uppercase of surrogates");
    }

    if (!UCharacter.toLowerCase(DESERET_dee + DESERET_DEE).equals(DESERET_dee + DESERET_dee)) {
        errln("Fails lowercase of surrogates");
    }
}
 
Example #24
Source File: RBBIRuleScanner.java    From j2objc with Apache License 2.0 6 votes vote down vote up
static String stripRules(String rules) {
    StringBuilder strippedRules = new StringBuilder();
    int rulesLength = rules.length();
    for (int idx = 0; idx < rulesLength;) {
        char ch = rules.charAt(idx++);
        if (ch == '#') {
            while (idx < rulesLength
                    && ch != '\r' && ch != '\n' && ch != chNEL) {
                ch = rules.charAt(idx++);
            }
        }
        if (!UCharacter.isISOControl(ch)) {
            strippedRules.append(ch);
        }
    }
    return strippedRules.toString();
}
 
Example #25
Source File: Utility.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Parse a Unicode identifier from the given string at the given
 * position.  Return the identifier, or null if there is no
 * identifier.
 * @param str the string to parse
 * @param pos INPUT-OUPUT parameter.  On INPUT, pos[0] is the
 * first character to examine.  It must be less than str.length(),
 * and it must not point to a whitespace character.  That is, must
 * have pos[0] < str.length().  On
 * OUTPUT, the position after the last parsed character.
 * @return the Unicode identifier, or null if there is no valid
 * identifier at pos[0].
 */
public static String parseUnicodeIdentifier(String str, int[] pos) {
    // assert(pos[0] < str.length());
    StringBuilder buf = new StringBuilder();
    int p = pos[0];
    while (p < str.length()) {
        int ch = Character.codePointAt(str, p);
        if (buf.length() == 0) {
            if (UCharacter.isUnicodeIdentifierStart(ch)) {
                buf.appendCodePoint(ch);
            } else {
                return null;
            }
        } else {
            if (UCharacter.isUnicodeIdentifierPart(ch)) {
                buf.appendCodePoint(ch);
            } else {
                break;
            }
        }
        p += UTF16.getCharCount(ch);
    }
    pos[0] = p;
    return buf.toString();
}
 
Example #26
Source File: UCharacterProperty.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
boolean contains(int c) {
    /* check ASCII and Fullwidth ASCII a-fA-F */
    if(
        (c<=0x66 && c>=0x41 && (c<=0x46 || c>=0x61)) ||
        (c>=0xff21 && c<=0xff46 && (c<=0xff26 || c>=0xff41))
    ) {
        return true;
    }
    return UCharacter.getType(c)==UCharacter.DECIMAL_DIGIT_NUMBER;
}
 
Example #27
Source File: BasicTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
 public void TestGetCombiningClass(){
    for(int i=0;i<0x10FFFF;i++){
        int cc = UCharacter.getCombiningClass(i);
        if(0xD800<= i && i<=0xDFFF && cc >0 ){
            cc = UCharacter.getCombiningClass(i);
            errln("CC: "+ cc + " for codepoint: " +Utility.hex(i,8));
        }
    }
}
 
Example #28
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 #29
Source File: IntTrieBuilder.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a 32 bit data from the table data
 * @param ch codepoint which data is to be retrieved
 * @return the 32 bit data
 */
public int getValue(int ch) 
{
    // valid, uncompacted trie and valid c?
    if (m_isCompacted_ || ch > UCharacter.MAX_VALUE || ch < 0) {
        return 0;
    }

    int block = m_index_[ch >> SHIFT_];
    return m_data_[Math.abs(block) + (ch & MASK_)];
}
 
Example #30
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test
public void TestGetEuropeanDigit(){
    //The number retrieved from 0xFF41 to 0xFF5A is due to
    //  exhaustive testing from UTF16.CODEPOINT_MIN_VALUE to
    //  UTF16.CODEPOINT_MAX_VALUE return a value of -1.

    int[] radixResult = {
            10,11,12,13,14,15,16,17,18,19,20,21,22,
            23,24,25,26,27,28,29,30,31,32,33,34,35};
    // Invalid and too-small-for-these-digits radix values.
    int[] radixCase1 = {0,1,5,10,100};
    // Radix values that work for at least some of the "digits".
    int[] radixCase2 = {12,16,20,36};

    for(int i=0xFF41; i<=0xFF5A; i++){
        for(int j=0; j < radixCase1.length; j++){
            if(UCharacter.digit(i, radixCase1[j]) != -1){
                errln("UCharacter.digit(int,int) was supposed to return -1 for radix " + radixCase1[j]
                        + ". Value passed: U+" + Integer.toHexString(i) + ". Got: " + UCharacter.digit(i, radixCase1[j]));
            }
        }
        for(int j=0; j < radixCase2.length; j++){
            int radix = radixCase2[j];
            int expected = (radixResult[i-0xFF41] < radix) ? radixResult[i-0xFF41] : -1;
            int actual = UCharacter.digit(i, radix);
            if(actual != expected){
                errln("UCharacter.digit(int,int) was supposed to return " +
                        expected + " for radix " + radix +
                        ". Value passed: U+" + Integer.toHexString(i) + ". Got: " + actual);
                break;
            }
        }
    }
}