01: /*
02: * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun in the LICENSE file that accompanied this code.
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: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
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 {
46: int maxNum = 2000; //TBD: Unicode 4.0 only has 1926 canoDecomp...
47: chars = new int[maxNum];
48: decomps = new String[maxNum];
49: decompNum = NormalizerImpl.getDecompose(chars, decomps);
50: }
51:
52: /**
53: * Construct a new <tt>ComposedCharIter</tt>. The iterator will return
54: * all Unicode characters with canonical decompositions, excluding Korean
55: * Hangul characters.
56: */
57: public ComposedCharIter() {
58: }
59:
60: /**
61: * Returns the next precomposed Unicode character.
62: * Repeated calls to <tt>next</tt> return all of the precomposed characters defined
63: * by Unicode, in ascending order. After all precomposed characters have
64: * been returned, {@link #hasNext} will return <tt>false</tt> and further calls
65: * to <tt>next</tt> will return {@link #DONE}.
66: */
67: public int next() {
68: if (curChar == decompNum - 1) {
69: return DONE;
70: }
71: return chars[++curChar];
72: }
73:
74: /**
75: * Returns the Unicode decomposition of the current character.
76: * This method returns the decomposition of the precomposed character most
77: * recently returned by {@link #next}. The resulting decomposition is
78: * affected by the settings of the options passed to the constructor.
79: */
80: public String decomposition() {
81: return decomps[curChar];
82: }
83:
84: private int curChar = -1;
85: }
|