Path: blob/master/src/java.base/share/classes/sun/text/SupplementaryCharacterData.java
41152 views
/*1* Copyright (c) 2003, 2012, 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;2627/**28* SupplementaryCharacterData is an SMI-private class which was written for29* RuleBasedBreakIterator and BreakDictionary.30*/31public final class SupplementaryCharacterData implements Cloneable {3233/**34* A token used as a character-category value to identify ignore characters35*/36private static final byte IGNORE = -1;3738/**39* An array for supplementary characters and values.40* Lower one byte is used to keep a byte-value.41* Upper three bytes are used to keep the first supplementary character42* which has the value. The value is also valid for the following43* supplementary characters until the next supplementary character in44* the array <code>dataTable</code>.45* For example, if the value of <code>dataTable[2]</code> is46* <code>0x01000123</code> and the value of <code>dataTable[3]</code> is47* <code>0x01000567</code>, supplementary characters from48* <code>0x10001</code> to <code>0x10004</code> has the value49* <code>0x23</code>. And, <code>getValue(0x10003)</code> returns the value.50*/51private int[] dataTable;525354/**55* Creates a new SupplementaryCharacterData object with the given table.56*/57public SupplementaryCharacterData(int[] table) {58dataTable = table;59}6061/**62* Returns a corresponding value for the given supplementary code-point.63*/64public int getValue(int index) {65// Index should be a valid supplementary character.66assert index >= Character.MIN_SUPPLEMENTARY_CODE_POINT &&67index <= Character.MAX_CODE_POINT :68"Invalid code point:" + Integer.toHexString(index);6970int i = 0;71int j = dataTable.length - 1;72int k;7374for (;;) {75k = (i + j) / 2;7677int start = dataTable[k] >> 8;78int end = dataTable[k+1] >> 8;7980if (index < start) {81j = k;82} else if (index > (end-1)) {83i = k;84} else {85int v = dataTable[k] & 0xFF;86return (v == 0xFF) ? IGNORE : v;87}88}89}9091/**92* Returns the data array.93*/94public int[] getArray() {95return dataTable;96}9798}99100101