2
|
1 |
/*
|
31680
|
2 |
* Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.text;
|
|
27 |
|
|
28 |
import sun.text.normalizer.NormalizerBase;
|
|
29 |
import sun.text.normalizer.NormalizerImpl;
|
|
30 |
|
|
31 |
public final class ComposedCharIter {
|
|
32 |
/**
|
|
33 |
* Constant that indicates the iteration has completed.
|
|
34 |
* {@link #next} returns this value when there are no more composed characters
|
|
35 |
* over which to iterate.
|
|
36 |
*/
|
|
37 |
public static final int DONE = NormalizerBase.DONE;
|
|
38 |
|
|
39 |
//cache the decomps mapping, so the seconde composedcharIter does
|
|
40 |
//not need to get the data again.
|
|
41 |
private static int chars[];
|
|
42 |
private static String decomps[];
|
|
43 |
private static int decompNum;
|
|
44 |
|
|
45 |
static {
|
31680
|
46 |
int maxNum = 2100;
|
2
|
47 |
chars = new int[maxNum];
|
|
48 |
decomps = new String[maxNum];
|
|
49 |
decompNum = NormalizerImpl.getDecompose(chars, decomps);
|
|
50 |
}
|
|
51 |
|
|
52 |
/**
|
30655
|
53 |
* Construct a new {@code ComposedCharIter}. The iterator will return
|
2
|
54 |
* all Unicode characters with canonical decompositions, excluding Korean
|
|
55 |
* Hangul characters.
|
|
56 |
*/
|
|
57 |
public ComposedCharIter() { }
|
|
58 |
|
|
59 |
/**
|
|
60 |
* Returns the next precomposed Unicode character.
|
30655
|
61 |
* Repeated calls to {@code next} return all of the precomposed characters defined
|
2
|
62 |
* by Unicode, in ascending order. After all precomposed characters have
|
30655
|
63 |
* been returned, {@link #hasNext} will return {@code false} and further calls
|
|
64 |
* to {@code next} will return {@link #DONE}.
|
2
|
65 |
*/
|
|
66 |
public int next() {
|
|
67 |
if (curChar == decompNum - 1) {
|
|
68 |
return DONE;
|
|
69 |
}
|
|
70 |
return chars[++curChar];
|
|
71 |
}
|
|
72 |
|
|
73 |
/**
|
|
74 |
* Returns the Unicode decomposition of the current character.
|
|
75 |
* This method returns the decomposition of the precomposed character most
|
|
76 |
* recently returned by {@link #next}. The resulting decomposition is
|
|
77 |
* affected by the settings of the options passed to the constructor.
|
|
78 |
*/
|
|
79 |
public String decomposition() {
|
|
80 |
return decomps[curChar];
|
|
81 |
}
|
|
82 |
private int curChar = -1;
|
|
83 |
}
|