0N/A/*
2362N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A *******************************************************************************
0N/A * (C) Copyright IBM Corp. 1996-2005 - All Rights Reserved *
0N/A * *
0N/A * The original version of this source code and documentation is copyrighted *
0N/A * and owned by IBM, These materials are provided under terms of a License *
0N/A * Agreement between IBM and Sun. This technology is protected by multiple *
0N/A * US and International patents. This notice and attribution to IBM may not *
0N/A * to removed. *
0N/A *******************************************************************************
0N/A */
0N/A
0N/Apackage java.text;
0N/A
0N/Aimport sun.text.normalizer.NormalizerBase;
0N/Aimport sun.text.normalizer.NormalizerImpl;
0N/A
0N/A/**
0N/A * This class provides the method <code>normalize</code> which transforms Unicode
0N/A * text into an equivalent composed or decomposed form, allowing for easier
0N/A * sorting and searching of text.
0N/A * The <code>normalize</code> method supports the standard normalization forms
0N/A * described in
0N/A * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">
0N/A * Unicode Standard Annex #15 &mdash; Unicode Normalization Forms</a>.
0N/A * <p>
0N/A * Characters with accents or other adornments can be encoded in
0N/A * several different ways in Unicode. For example, take the character A-acute.
0N/A * In Unicode, this can be encoded as a single character (the "composed" form):
0N/A *
0N/A * <p><pre>
0N/A * U+00C1 LATIN CAPITAL LETTER A WITH ACUTE</pre>
0N/A * </p>
0N/A *
0N/A * or as two separate characters (the "decomposed" form):
0N/A *
0N/A * <p><pre>
0N/A * U+0041 LATIN CAPITAL LETTER A
0N/A * U+0301 COMBINING ACUTE ACCENT</pre>
0N/A * </p>
0N/A *
0N/A * To a user of your program, however, both of these sequences should be
0N/A * treated as the same "user-level" character "A with acute accent". When you
0N/A * are searching or comparing text, you must ensure that these two sequences are
0N/A * treated as equivalent. In addition, you must handle characters with more than
0N/A * one accent. Sometimes the order of a character's combining accents is
0N/A * significant, while in other cases accent sequences in different orders are
0N/A * really equivalent.
0N/A * <p>
0N/A * Similarly, the string "ffi" can be encoded as three separate letters:
0N/A *
0N/A * <p><pre>
0N/A * U+0066 LATIN SMALL LETTER F
0N/A * U+0066 LATIN SMALL LETTER F
0N/A * U+0069 LATIN SMALL LETTER I</pre>
0N/A * </p>
0N/A *
0N/A * or as the single character
0N/A *
0N/A * <p><pre>
0N/A * U+FB03 LATIN SMALL LIGATURE FFI</pre>
0N/A * </p>
0N/A *
0N/A * The ffi ligature is not a distinct semantic character, and strictly speaking
0N/A * it shouldn't be in Unicode at all, but it was included for compatibility
0N/A * with existing character sets that already provided it. The Unicode standard
0N/A * identifies such characters by giving them "compatibility" decompositions
0N/A * into the corresponding semantic characters. When sorting and searching, you
0N/A * will often want to use these mappings.
0N/A * <p>
0N/A * The <code>normalize</code> method helps solve these problems by transforming
0N/A * text into the canonical composed and decomposed forms as shown in the first
0N/A * example above. In addition, you can have it perform compatibility
0N/A * decompositions so that you can treat compatibility characters the same as
0N/A * their equivalents.
0N/A * Finally, the <code>normalize</code> method rearranges accents into the
0N/A * proper canonical order, so that you do not have to worry about accent
0N/A * rearrangement on your own.
0N/A * <p>
0N/A * The W3C generally recommends to exchange texts in NFC.
0N/A * Note also that most legacy character encodings use only precomposed forms and
0N/A * often do not encode any combining marks by themselves. For conversion to such
0N/A * character encodings the Unicode text needs to be normalized to NFC.
0N/A * For more usage examples, see the Unicode Standard Annex.
0N/A *
0N/A * @since 1.6
0N/A */
0N/Apublic final class Normalizer {
0N/A
0N/A private Normalizer() {};
0N/A
0N/A /**
0N/A * This enum provides constants of the four Unicode normalization forms
0N/A * that are described in
0N/A * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">
0N/A * Unicode Standard Annex #15 &mdash; Unicode Normalization Forms</a>
0N/A * and two methods to access them.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public static enum Form {
0N/A
0N/A /**
0N/A * Canonical decomposition.
0N/A */
0N/A NFD,
0N/A
0N/A /**
0N/A * Canonical decomposition, followed by canonical composition.
0N/A */
0N/A NFC,
0N/A
0N/A /**
0N/A * Compatibility decomposition.
0N/A */
0N/A NFKD,
0N/A
0N/A /**
0N/A * Compatibility decomposition, followed by canonical composition.
0N/A */
0N/A NFKC
0N/A }
0N/A
0N/A /**
0N/A * Normalize a sequence of char values.
0N/A * The sequence will be normalized according to the specified normalization
0N/A * from.
0N/A * @param src The sequence of char values to normalize.
0N/A * @param form The normalization form; one of
0N/A * {@link java.text.Normalizer.Form#NFC},
0N/A * {@link java.text.Normalizer.Form#NFD},
0N/A * {@link java.text.Normalizer.Form#NFKC},
0N/A * {@link java.text.Normalizer.Form#NFKD}
0N/A * @return The normalized String
0N/A * @throws NullPointerException If <code>src</code> or <code>form</code>
0N/A * is null.
0N/A */
0N/A public static String normalize(CharSequence src, Form form) {
0N/A return NormalizerBase.normalize(src.toString(), form);
0N/A }
0N/A
0N/A /**
0N/A * Determines if the given sequence of char values is normalized.
0N/A * @param src The sequence of char values to be checked.
0N/A * @param form The normalization form; one of
0N/A * {@link java.text.Normalizer.Form#NFC},
0N/A * {@link java.text.Normalizer.Form#NFD},
0N/A * {@link java.text.Normalizer.Form#NFKC},
0N/A * {@link java.text.Normalizer.Form#NFKD}
0N/A * @return true if the sequence of char values is normalized;
0N/A * false otherwise.
0N/A * @throws NullPointerException If <code>src</code> or <code>form</code>
0N/A * is null.
0N/A */
0N/A public static boolean isNormalized(CharSequence src, Form form) {
0N/A return NormalizerBase.isNormalized(src.toString(), form);
0N/A }
0N/A}