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

The following examples show how to use android.icu.lang.UCharacter#isDefined() . 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: UCharacterTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
* Tests for defined and undefined characters
*/
@Test
public void TestDefined()
{
    int undefined[] = {0xfff1, 0xfff7, 0xfa6e};
    int defined[] = {0x523E, 0x004f88, 0x00fffd};

    int size = undefined.length;
    for (int i = 0; i < size; i ++)
    {
        if (UCharacter.isDefined(undefined[i]))
        {
            errln("FAIL \\u" + hex(undefined[i]) +
                        " expected not to be defined");
            break;
        }
        if (!UCharacter.isDefined(defined[i]))
        {
            errln("FAIL \\u" + hex(defined[i]) + " expected defined");
            break;
        }
    }
}
 
Example 2
Source File: CollationIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test for CollationElementIterator previous and next for the whole set of
 * unicode characters.
 */
@Test
public void TestUnicodeChar() {
    RuleBasedCollator en_us = (RuleBasedCollator)Collator.getInstance(Locale.US);
    CollationElementIterator iter;
    char codepoint;
    StringBuffer source = new StringBuffer();
    source.append("\u0e4d\u0e4e\u0e4f");
    // source.append("\u04e8\u04e9");
    iter = en_us.getCollationElementIterator(source.toString());
    // A basic test to see if it's working at all 
    CollationTest.backAndForth(this, iter);
    for (codepoint = 1; codepoint < 0xFFFE;) {
        source.delete(0, source.length());
        while (codepoint % 0xFF != 0) {
            if (UCharacter.isDefined(codepoint)) {
                source.append(codepoint);
            }
            codepoint ++;
        }
        
        if (UCharacter.isDefined(codepoint)) {
            source.append(codepoint);
        }
        
        if (codepoint != 0xFFFF) {
            codepoint ++;
        }
        /*if (codepoint >= 0x04fc) {
            System.out.println("codepoint " + Integer.toHexString(codepoint));
            String str = source.substring(230, 232);
            System.out.println(android.icu.impl.Utility.escape(str));
            System.out.println("codepoint " + Integer.toHexString(codepoint) 
                               + "length " + str.length());
            iter = en_us.getCollationElementIterator(str);
            CollationTest.backAndForth(this, iter);
        }
        */
        iter = en_us.getCollationElementIterator(source.toString());
        // A basic test to see if it's working at all 
        CollationTest.backAndForth(this, iter);
    }
}
 
Example 3
Source File: CollationIteratorTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test for CollationElementIterator previous and next for the whole set of
 * unicode characters with normalization on.
 */
@Test
public void TestNormalizedUnicodeChar()
{
    // thai should have normalization on
    RuleBasedCollator th_th = null;
    try {
        th_th = (RuleBasedCollator)Collator.getInstance(
                                                   new Locale("th", "TH"));
    } catch (Exception e) {
        warnln("Error creating Thai collator");
        return;
    }
    StringBuffer source = new StringBuffer();
    source.append('\uFDFA');
    CollationElementIterator iter 
                    = th_th.getCollationElementIterator(source.toString());
    CollationTest.backAndForth(this, iter);
    for (char codepoint = 0x1; codepoint < 0xfffe;) {
        source.delete(0, source.length());
        while (codepoint % 0xFF != 0) {
            if (UCharacter.isDefined(codepoint)) {
                source.append(codepoint);
            }
            codepoint ++;
        }
        
        if (UCharacter.isDefined(codepoint)) {
            source.append(codepoint);
        }
        
        if (codepoint != 0xFFFF) {
            codepoint ++;
        }
        
        /*if (((int)codepoint) >= 0xfe00) {
            String str = source.substring(185, 190);
            System.out.println(android.icu.impl.Utility.escape(str));
            System.out.println("codepoint " 
                               + Integer.toHexString(codepoint) 
                               + "length " + str.length());
            iter = th_th.getCollationElementIterator(str);
            CollationTest.backAndForth(this, iter);
        */
        iter = th_th.getCollationElementIterator(source.toString());
        // A basic test to see if it's working at all 
        CollationTest.backAndForth(this, iter);
    }
}
 
Example 4
Source File: UCharacterCompare.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Main testing method
 */
public static void main(String arg[]) {
    System.out.println("Starting character compare");
    try {
        FileWriter f;
        if (arg.length == 0)
            f = new FileWriter("compare.txt");
        else
            f = new FileWriter(arg[0]);
        PrintWriter p = new PrintWriter(f);
        p.print("char  character name                                                           ");
        p.println("method name               ucharacter character");
        for (char i = Character.MIN_VALUE; i < Character.MAX_VALUE; i++) {
            System.out.println("character \\u" + Integer.toHexString(i));
            if (UCharacter.isDefined(i) != Character.isDefined(i))
                trackDifference(p, i, "isDefined()", "" + UCharacter.isDefined(i), "" + Character.isDefined(i));
            else {
                if (UCharacter.digit(i, 10) != Character.digit(i, 10))
                    trackDifference(p, i, "digit()", "" + UCharacter.digit(i, 10), "" + Character.digit(i, 10));
                if (UCharacter.getNumericValue(i) != Character.getNumericValue(i))
                    trackDifference(p, i, "getNumericValue()", "" + UCharacter.getNumericValue(i), ""
                            + Character.getNumericValue(i));
                if (!compareType(UCharacter.getType(i), Character.getType(i)))
                    trackDifference(p, i, "getType()", "" + UCharacter.getType(i), "" + Character.getType(i));
                if (UCharacter.isDigit(i) != Character.isDigit(i))
                    trackDifference(p, i, "isDigit()", "" + UCharacter.isDigit(i), "" + Character.isDigit(i));
                if (UCharacter.isISOControl(i) != Character.isISOControl(i))
                    trackDifference(p, i, "isISOControl()", "" + UCharacter.isISOControl(i), ""
                            + Character.isISOControl(i));
                if (UCharacter.isLetter(i) != Character.isLetter(i))
                    trackDifference(p, i, "isLetter()", "" + UCharacter.isLetter(i), "" + Character.isLetter(i));
                if (UCharacter.isLetterOrDigit(i) != Character.isLetterOrDigit(i))
                    trackDifference(p, i, "isLetterOrDigit()", "" + UCharacter.isLetterOrDigit(i), ""
                            + Character.isLetterOrDigit(i));
                if (UCharacter.isLowerCase(i) != Character.isLowerCase(i))
                    trackDifference(p, i, "isLowerCase()", "" + UCharacter.isLowerCase(i), ""
                            + Character.isLowerCase(i));
                if (UCharacter.isWhitespace(i) != Character.isWhitespace(i))
                    trackDifference(p, i, "isWhitespace()", "" + UCharacter.isWhitespace(i), ""
                            + Character.isWhitespace(i));
                if (UCharacter.isSpaceChar(i) != Character.isSpaceChar(i))
                    trackDifference(p, i, "isSpaceChar()", "" + UCharacter.isSpaceChar(i), ""
                            + Character.isSpaceChar(i));
                if (UCharacter.isTitleCase(i) != Character.isTitleCase(i))
                    trackDifference(p, i, "isTitleChar()", "" + UCharacter.isTitleCase(i), ""
                            + Character.isTitleCase(i));
                if (UCharacter.isUnicodeIdentifierPart(i) != Character.isUnicodeIdentifierPart(i))
                    trackDifference(p, i, "isUnicodeIdentifierPart()", "" + UCharacter.isUnicodeIdentifierPart(i),
                            "" + Character.isUnicodeIdentifierPart(i));
                if (UCharacter.isUnicodeIdentifierStart(i) != Character.isUnicodeIdentifierStart(i))
                    trackDifference(p, i, "isUnicodeIdentifierStart()",
                            "" + UCharacter.isUnicodeIdentifierStart(i), "" + Character.isUnicodeIdentifierStart(i));
                if (UCharacter.isIdentifierIgnorable(i) != Character.isIdentifierIgnorable(i))
                    trackDifference(p, i, "isIdentifierIgnorable()", "" + UCharacter.isIdentifierIgnorable(i), ""
                            + Character.isIdentifierIgnorable(i));
                if (UCharacter.isUpperCase(i) != Character.isUpperCase(i))
                    trackDifference(p, i, "isUpperCase()", "" + UCharacter.isUpperCase(i), ""
                            + Character.isUpperCase(i));
                if (UCharacter.toLowerCase(i) != Character.toLowerCase(i))
                    trackDifference(p, i, "toLowerCase()", Integer.toHexString(UCharacter.toLowerCase(i)), Integer
                            .toHexString(Character.toLowerCase(i)));
                if (!UCharacter.toString(i).equals(new Character(i).toString()))
                    trackDifference(p, i, "toString()", UCharacter.toString(i), new Character(i).toString());
                if (UCharacter.toTitleCase(i) != Character.toTitleCase(i))
                    trackDifference(p, i, "toTitleCase()", Integer.toHexString(UCharacter.toTitleCase(i)), Integer
                            .toHexString(Character.toTitleCase(i)));
                if (UCharacter.toUpperCase(i) != Character.toUpperCase(i))
                    trackDifference(p, i, "toUpperCase()", Integer.toHexString(UCharacter.toUpperCase(i)), Integer
                            .toHexString(Character.toUpperCase(i)));
            }
        }
        summary(p);
        p.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}