Search in sources :

Example 1 with Norm2AllModes

use of android.icu.impl.Norm2AllModes in project j2objc by google.

the class Normalizer2 method getInstance.

/**
 * Returns a Normalizer2 instance which uses the specified data file
 * (an ICU data file if data=null, or else custom binary data)
 * and which composes or decomposes text according to the specified mode.
 * Returns an unmodifiable singleton instance.
 * <ul>
 * <li>Use data=null for data files that are part of ICU's own data.
 * <li>Use name="nfc" and COMPOSE/DECOMPOSE for Unicode standard NFC/NFD.
 * <li>Use name="nfkc" and COMPOSE/DECOMPOSE for Unicode standard NFKC/NFKD.
 * <li>Use name="nfkc_cf" and COMPOSE for Unicode standard NFKC_CF=NFKC_Casefold.
 * </ul>
 * If data!=null, then the binary data is read once and cached using the provided
 * name as the key.
 * If you know or expect the data to be cached already, you can use data!=null
 * for non-ICU data as well.
 * <p>Any {@link java.io.IOException} is wrapped into a {@link android.icu.util.ICUUncheckedIOException}.
 * @param data the binary, big-endian normalization (.nrm file) data, or null for ICU data
 * @param name "nfc" or "nfkc" or "nfkc_cf" or name of custom data file
 * @param mode normalization mode (compose or decompose etc.)
 * @return the requested Normalizer2, if successful
 */
public static Normalizer2 getInstance(InputStream data, String name, Mode mode) {
    // TODO: If callers really use this API, then we should add an overload that takes a ByteBuffer.
    ByteBuffer bytes = null;
    if (data != null) {
        try {
            bytes = ICUBinary.getByteBufferFromInputStreamAndCloseStream(data);
        } catch (IOException e) {
            throw new ICUUncheckedIOException(e);
        }
    }
    Norm2AllModes all2Modes = Norm2AllModes.getInstance(bytes, name);
    switch(mode) {
        case COMPOSE:
            return all2Modes.comp;
        case DECOMPOSE:
            return all2Modes.decomp;
        case FCD:
            return all2Modes.fcd;
        case COMPOSE_CONTIGUOUS:
            return all2Modes.fcc;
        // will not occur
        default:
            return null;
    }
}
Also used : Norm2AllModes(android.icu.impl.Norm2AllModes) ICUUncheckedIOException(android.icu.util.ICUUncheckedIOException) ICUUncheckedIOException(android.icu.util.ICUUncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Norm2AllModes (android.icu.impl.Norm2AllModes)1 ICUUncheckedIOException (android.icu.util.ICUUncheckedIOException)1 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1