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

The following examples show how to use android.icu.lang.UCharacter#getExtendedName() . 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: UCharacterCompare.java    From j2objc with Apache License 2.0 9 votes vote down vote up
/**
 * Difference writing to file
 * 
 * @param f
 *            file outputstream
 * @param ch
 *            code point
 * @param method
 *            for testing
 * @param ucharval
 *            UCharacter value after running method
 * @param charval
 *            Character value after running method
 */
private static void trackDifference(PrintWriter f, int ch, String method, String ucharval, String charval)
        throws Exception {
    if (m_hashtable_.containsKey(method)) {
        Integer value = m_hashtable_.get(method);
        m_hashtable_.put(method, new Integer(value.intValue() + 1));
    } else
        m_hashtable_.put(method, new Integer(1));

    String temp = Integer.toHexString(ch);
    StringBuffer s = new StringBuffer(temp);
    for (int i = 0; i < 6 - temp.length(); i++)
        s.append(' ');
    temp = UCharacter.getExtendedName(ch);
    if (temp == null)
        temp = " ";
    s.append(temp);
    for (int i = 0; i < 73 - temp.length(); i++)
        s.append(' ');

    s.append(method);
    for (int i = 0; i < 27 - method.length(); i++)
        s.append(' ');
    s.append(ucharval);
    for (int i = 0; i < 11 - ucharval.length(); i++)
        s.append(' ');
    s.append(charval);
    f.println(s.toString());
}
 
Example 2
Source File: UnicodeNameTransliterator.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Implements {@link Transliterator#handleTransliterate}.
 */
@Override
protected void handleTransliterate(Replaceable text,
                                   Position offsets, boolean isIncremental) {
    int cursor = offsets.start;
    int limit = offsets.limit;

    StringBuilder str = new StringBuilder();
    str.append(OPEN_DELIM);
    int len;
    String name;

    while (cursor < limit) {
        int c = text.char32At(cursor);
        if ((name=UCharacter.getExtendedName(c)) != null) {

            str.setLength(OPEN_DELIM_LEN);
            str.append(name).append(CLOSE_DELIM);

            int clen = UTF16.getCharCount(c);
            text.replace(cursor, cursor+clen, str.toString());
            len = str.length();
            cursor += len; // advance cursor by 1 and adjust for new text
            limit += len-clen; // change in length
        } else {
            ++cursor;
        }
    }

    offsets.contextLimit += limit - offsets.limit;
    offsets.limit = limit;
    offsets.start = cursor;
}
 
Example 3
Source File: TrieMapTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Before
public void init() throws Exception {
    if (unicodeTestMap.size() == 0) {
        if (TestFmwk.getExhaustiveness() < 5) {
            logln("\tShort version, timing for 1s:\t to get more accurate figures and test for reasonable times, use -e5 or more");
            t.setTimingPeriod(1*Timer.SECONDS);
        } else {
            int seconds = TestFmwk.getExhaustiveness();
            logln("\tExhaustive version, timing for " + seconds + "s");
            t.setTimingPeriod(seconds*Timer.SECONDS);
            useSmallList = false;
        }

        int i = 0;
        UnicodeSet testSet = new UnicodeSet("[[:^C:]-[:sc=han:]]");
        for (String s : testSet) {
            int codePoint = s.codePointAt(0);
            String extendedName = UCharacter.getExtendedName(codePoint);
            if (!unicodeTestMap.containsKey(extendedName)) {
                unicodeTestMap.put(extendedName, i++);
            }
            if (i > 500 && useSmallList) break;
        }
        ULocale[] locales = useSmallList ? new ULocale[] {new ULocale("zh"), new ULocale("el")} : ULocale.getAvailableLocales();
        for (ULocale locale : locales) {
            if (locale.getDisplayCountry().length() != 0) {
                continue;
            }
            String localeName;
            for (String languageCode : ULocale.getISOLanguages()) {
                localeName = ULocale.getDisplayName(languageCode, locale);
                if (!localeName.equals(languageCode)) {
                    if (!unicodeTestMap.containsKey(localeName)) {
                        unicodeTestMap.put(localeName, MASK & i++);
                    }
                    if (SHORT) break;
                }
            }
            for (String countryCode : ULocale.getISOCountries()) {
                localeName = ULocale.getDisplayCountry("und-" + countryCode, locale);
                if (!localeName.equals(countryCode)) {
                    if (!unicodeTestMap.containsKey(localeName)) {
                        unicodeTestMap.put(localeName, MASK & i++);
                    }
                    if (SHORT) break;
                }
            }
        }
        int charCount = 0; 
        for (String key : unicodeTestMap.keySet()) {
            charCount += key.length();
        }
        logln("\tTest Data Elements:\t\t\t" + nf.format(unicodeTestMap.size()));
        logln("\tTotal chars:\t\t\t" + nf.format(charCount));
    }
}