Path: blob/master/src/java.base/share/classes/sun/text/ComposedCharIter.java
41152 views
/*1* Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.text;2627import jdk.internal.icu.impl.NormalizerImpl;28import jdk.internal.icu.text.NormalizerBase;2930public final class ComposedCharIter {31/**32* Constant that indicates the iteration has completed.33* {@link #next} returns this value when there are no more composed characters34* over which to iterate.35*/36public static final int DONE = NormalizerBase.DONE;3738//cache the decomps mapping, so the seconde composedcharIter does39//not need to get the data again.40private static int chars[];41private static String decomps[];42private static int decompNum;4344static {45int maxNum = 2100;46chars = new int[maxNum];47decomps = new String[maxNum];48decompNum = NormalizerImpl.getDecompose(chars, decomps);49}5051/**52* Construct a new {@code ComposedCharIter}. The iterator will return53* all Unicode characters with canonical decompositions, excluding Korean54* Hangul characters.55*/56public ComposedCharIter() { }5758/**59* Returns the next precomposed Unicode character.60* Repeated calls to {@code next} return all of the precomposed characters defined61* by Unicode, in ascending order. After all precomposed characters have62* been returned, {@link #hasNext} will return {@code false} and further calls63* to {@code next} will return {@link #DONE}.64*/65public int next() {66if (curChar == decompNum - 1) {67return DONE;68}69return chars[++curChar];70}7172/**73* Returns the Unicode decomposition of the current character.74* This method returns the decomposition of the precomposed character most75* recently returned by {@link #next}. The resulting decomposition is76* affected by the settings of the options passed to the constructor.77*/78public String decomposition() {79return decomps[curChar];80}81private int curChar = -1;82}838485