• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package java.text;
18 
19 import libcore.icu.NativeNormalizer;
20 
21 /**
22  * Provides normalization functions according to
23  * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode Standard Annex #15:
24  * Unicode Normalization Forms</a>. Normalization can decompose and compose
25  * characters for equivalency checking.
26  *
27  * @since 1.6
28  */
29 public final class Normalizer {
30     /**
31      * The normalization forms supported by the Normalizer. These are specified in
32      * <a href="http://www.unicode.org/unicode/reports/tr15/tr15-23.html">Unicode Standard
33      * Annex #15</a>.
34      */
35     public static enum Form {
36         /**
37          * Normalization Form D - Canonical Decomposition.
38          */
39         NFD,
40 
41         /**
42          * Normalization Form C - Canonical Decomposition, followed by Canonical Composition.
43          */
44         NFC,
45 
46         /**
47          * Normalization Form KD - Compatibility Decomposition.
48          */
49         NFKD,
50 
51         /**
52          * Normalization Form KC - Compatibility Decomposition, followed by Canonical Composition.
53          */
54         NFKC;
55     }
56 
57     /**
58      * Check whether the given character sequence <code>src</code> is normalized
59      * according to the normalization method <code>form</code>.
60      *
61      * @param src character sequence to check
62      * @param form normalization form to check against
63      * @return true if normalized according to <code>form</code>
64      */
isNormalized(CharSequence src, Form form)65     public static boolean isNormalized(CharSequence src, Form form) {
66         return NativeNormalizer.isNormalized(src, form);
67     }
68 
69     /**
70      * Normalize the character sequence <code>src</code> according to the
71      * normalization method <code>form</code>.
72      *
73      * @param src character sequence to read for normalization
74      * @param form normalization form
75      * @return string normalized according to <code>form</code>
76      */
normalize(CharSequence src, Form form)77     public static String normalize(CharSequence src, Form form) {
78         return NativeNormalizer.normalize(src, form);
79     }
80 
Normalizer()81     private Normalizer() {}
82 }
83