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

The following examples show how to use android.icu.lang.UCharacter#isUnicodeIdentifierPart() . 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: RBBISymbolTable.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public String parseReference(String text, ParsePosition pos, int limit) {
    int start = pos.getIndex();
    int i = start;
    String result = "";
    while (i < limit) {
        int c = UTF16.charAt(text, i);
        if ((i == start && !UCharacter.isUnicodeIdentifierStart(c))
                || !UCharacter.isUnicodeIdentifierPart(c)) {
            break;
        }
        i += UTF16.getCharCount(c);
    }
    if (i == start) { // No valid name chars
        return result; // Indicate failure with empty string
    }
    pos.setIndex(i);
    result = text.substring(start, i);
    return result;
}
 
Example 2
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 3
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 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();
    }
}
 
Example 5
Source File: UCharacterTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
* Testing for identifier characters
*/
@Test
public void TestIdentifier()
{
    int unicodeidstart[] = {0x0250, 0x0000e2, 0x000061};
    int nonunicodeidstart[] = {0x2000, 0x00000a, 0x002019};
    int unicodeidpart[] = {0x005f, 0x000032, 0x000045};
    int nonunicodeidpart[] = {0x2030, 0x0000a3, 0x000020};
    int idignore[] = {0x0006, 0x0010, 0x206b};
    int nonidignore[] = {0x0075, 0x0000a3, 0x000061};

    int size = unicodeidstart.length;
    for (int i = 0; i < size; i ++)
    {
        if (!UCharacter.isUnicodeIdentifierStart(unicodeidstart[i]))
        {
            errln("FAIL \\u" + hex(unicodeidstart[i]) +
                " expected to be a unicode identifier start character");
            break;
        }
        if (UCharacter.isUnicodeIdentifierStart(nonunicodeidstart[i]))
        {
            errln("FAIL \\u" + hex(nonunicodeidstart[i]) +
                    " expected not to be a unicode identifier start " +
                    "character");
            break;
        }
        if (!UCharacter.isUnicodeIdentifierPart(unicodeidpart[i]))
        {
            errln("FAIL \\u" + hex(unicodeidpart[i]) +
                " expected to be a unicode identifier part character");
            break;
        }
        if (UCharacter.isUnicodeIdentifierPart(nonunicodeidpart[i]))
        {
            errln("FAIL \\u" + hex(nonunicodeidpart[i]) +
                    " expected not to be a unicode identifier part " +
                    "character");
            break;
        }
        if (!UCharacter.isIdentifierIgnorable(idignore[i]))
        {
            errln("FAIL \\u" + hex(idignore[i]) +
                    " expected to be a ignorable unicode character");
            break;
        }
        if (UCharacter.isIdentifierIgnorable(nonidignore[i]))
        {
            errln("FAIL \\u" + hex(nonidignore[i]) +
                " expected not to be a ignorable unicode character");
            break;
        }
        logln("Ok    \\u" + hex(unicodeidstart[i]) + " and \\u" +
                hex(nonunicodeidstart[i]) + " and \\u" +
                hex(unicodeidpart[i]) + " and \\u" +
                hex(nonunicodeidpart[i]) + " and \\u" +
                hex(idignore[i]) + " and \\u" + hex(nonidignore[i]));
    }
}