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

The following examples show how to use android.icu.lang.UCharacter#isDigit() . 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: UCharacterProperty.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override
boolean contains(int c) {
    return UCharacter.isUAlphabetic(c) || UCharacter.isDigit(c);
}
 
Example 2
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();
    }
}
 
Example 3
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
* Testing the letter and number determination in UCharacter
*/
@Test
public void TestLetterNumber()
{
    for (int i = 0x0041; i < 0x005B; i ++)
    if (!UCharacter.isLetter(i))
        errln("FAIL \\u" + hex(i) + " expected to be a letter");

    for (int i = 0x0660; i < 0x066A; i ++)
    if (UCharacter.isLetter(i))
        errln("FAIL \\u" + hex(i) + " expected not to be a letter");

    for (int i = 0x0660; i < 0x066A; i ++)
    if (!UCharacter.isDigit(i))
        errln("FAIL \\u" + hex(i) + " expected to be a digit");

    for (int i = 0x0041; i < 0x005B; i ++)
        if (!UCharacter.isLetterOrDigit(i))
            errln("FAIL \\u" + hex(i) + " expected not to be a digit");

    for (int i = 0x0660; i < 0x066A; i ++)
        if (!UCharacter.isLetterOrDigit(i))
            errln("FAIL \\u" + hex(i) +
                "expected to be either a letter or a digit");

    /*
     * The following checks work only starting from Unicode 4.0.
     * Check the version number here.
     */
    VersionInfo version =    UCharacter.getUnicodeVersion();
    if(version.getMajor()<4 || version.equals(VersionInfo.getInstance(4, 0, 1))) {
        return;
    }



    /*
     * Sanity check:
     * Verify that exactly the digit characters have decimal digit values.
     * This assumption is used in the implementation of u_digit()
     * (which checks nt=de)
     * compared with the parallel java.lang.Character.digit()
     * (which checks Nd).
     *
     * This was not true in Unicode 3.2 and earlier.
     * Unicode 4.0 fixed discrepancies.
     * Unicode 4.0.1 re-introduced problems in this area due to an
     * unintentionally incomplete last-minute change.
     */
    String digitsPattern = "[:Nd:]";
    String decimalValuesPattern = "[:Numeric_Type=Decimal:]";

    UnicodeSet digits, decimalValues;

    digits= new UnicodeSet(digitsPattern);
    decimalValues=new UnicodeSet(decimalValuesPattern);


    compareUSets(digits, decimalValues, "[:Nd:]", "[:Numeric_Type=Decimal:]", true);


}
 
Example 4
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
* Tests for digit characters
*/
@Test
public void TestDigits()
{
    int digits[] = {0x0030, 0x000662, 0x000F23, 0x000ED5, 0x002160};

    //special characters not in the properties table
    int digits2[] = {0x3007, 0x004e00, 0x004e8c, 0x004e09, 0x0056d8,
                     0x004e94, 0x00516d, 0x4e03, 0x00516b, 0x004e5d};
    int nondigits[] = {0x0010, 0x000041, 0x000122, 0x0068FE};

    int digitvalues[] = {0, 2, 3, 5, 1};
    int digitvalues2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    int size  = digits.length;
    for (int i = 0; i < size; i ++) {
        if (UCharacter.isDigit(digits[i]) &&
            UCharacter.digit(digits[i]) != digitvalues[i])
        {
            errln("FAIL \\u" + hex(digits[i]) +
                    " expected digit with value " + digitvalues[i]);
            break;
        }
    }
    size = nondigits.length;
    for (int i = 0; i < size; i ++)
        if (UCharacter.isDigit(nondigits[i]))
        {
            errln("FAIL \\u" + hex(nondigits[i]) + " expected nondigit");
            break;
        }

    size = digits2.length;
    for (int i = 0; i < 10; i ++) {
        if (UCharacter.isDigit(digits2[i]) &&
            UCharacter.digit(digits2[i]) != digitvalues2[i])
        {
            errln("FAIL \\u" + hex(digits2[i]) +
                " expected digit with value " + digitvalues2[i]);
            break;
        }
    }
}