All Downloads are FREE. Search and download functionalities are using the official Maven repository.

java.text.Normalizer Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package java.text;

import libcore.icu.NativeNormalizer;

/**
 * Provides normalization functions according to
 * Unicode Standard Annex #15:
 * Unicode Normalization Forms. Normalization can decompose and compose
 * characters for equivalency checking.
 *
 * @since 1.6
 */
public final class Normalizer {
    /**
     * The normalization forms supported by the Normalizer. These are specified in
     * Unicode Standard
     * Annex #15.
     */
    public static enum Form {
        /**
         * Normalization Form D - Canonical Decomposition.
         */
        NFD,

        /**
         * Normalization Form C - Canonical Decomposition, followed by Canonical Composition.
         */
        NFC,

        /**
         * Normalization Form KD - Compatibility Decomposition.
         */
        NFKD,

        /**
         * Normalization Form KC - Compatibility Decomposition, followed by Canonical Composition.
         */
        NFKC;
    }

    /**
     * Check whether the given character sequence src is normalized
     * according to the normalization method form.
     *
     * @param src character sequence to check
     * @param form normalization form to check against
     * @return true if normalized according to form
     */
    public static boolean isNormalized(CharSequence src, Form form) {
        return NativeNormalizer.isNormalized(src, form);
    }

    /**
     * Normalize the character sequence src according to the
     * normalization method form.
     *
     * @param src character sequence to read for normalization
     * @param form normalization form
     * @return string normalized according to form
     */
    public static String normalize(CharSequence src, Form form) {
        return NativeNormalizer.normalize(src, form);
    }

    private Normalizer() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy