mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-09 07:22:11 +00:00
ICU-6926 set svn properties
X-SVN-Rev: 26123
This commit is contained in:
parent
fb6a056259
commit
9f48e1a767
4 changed files with 1024 additions and 1043 deletions
19
.gitattributes
vendored
19
.gitattributes
vendored
|
@ -64,14 +64,10 @@ icu4j/main/classes/charset/.classpath -text
|
|||
icu4j/main/classes/charset/.project -text
|
||||
icu4j/main/classes/charset/.settings/org.eclipse.jdt.core.prefs -text
|
||||
icu4j/main/classes/charset/manifest.stub -text
|
||||
icu4j/main/classes/charset/src/com/ibm/icu/charset/CharsetSelector.java -text
|
||||
icu4j/main/classes/core/.classpath -text
|
||||
icu4j/main/classes/core/.project -text
|
||||
icu4j/main/classes/core/.settings/org.eclipse.jdt.core.prefs -text
|
||||
icu4j/main/classes/core/manifest.stub -text
|
||||
icu4j/main/classes/core/src/com/ibm/icu/impl/PVecToTrieCompactHandler.java -text
|
||||
icu4j/main/classes/core/src/com/ibm/icu/impl/PropsVectors.java -text
|
||||
icu4j/main/classes/core/src/com/ibm/icu/text/NumberingSystem.java -text
|
||||
icu4j/main/classes/localespi/.classpath -text
|
||||
icu4j/main/classes/localespi/.project -text
|
||||
icu4j/main/classes/localespi/.settings/org.eclipse.jdt.core.prefs -text
|
||||
|
@ -93,15 +89,12 @@ icu4j/main/tests/charset/.classpath -text
|
|||
icu4j/main/tests/charset/.project -text
|
||||
icu4j/main/tests/charset/.settings/org.eclipse.jdt.core.prefs -text
|
||||
icu4j/main/tests/charset/manifest.stub -text
|
||||
icu4j/main/tests/charset/src/com/ibm/icu/dev/test/charset/TestSelection.java -text
|
||||
icu4j/main/tests/core/.classpath -text
|
||||
icu4j/main/tests/core/.project -text
|
||||
icu4j/main/tests/core/.settings/org.eclipse.jdt.core.prefs -text
|
||||
icu4j/main/tests/core/manifest.stub -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/data/rbbi/english.dict -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/data/thai6.ucs -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/test/duration/RegressionTest.java -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/test/rbbi/rbbitst.txt -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.impl.OlsonTimeZone.dat -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.impl.TimeZoneAdapter.dat -text
|
||||
icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/data/ICU_3.6/com.ibm.icu.math.BigDecimal.dat -text
|
||||
|
@ -241,18 +234,6 @@ icu4j/main/tests/framework/manifest.stub -text
|
|||
icu4j/main/tests/localespi/.classpath -text
|
||||
icu4j/main/tests/localespi/.project -text
|
||||
icu4j/main/tests/localespi/manifest.stub -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Asian.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Chinese.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Japanese.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Japanese_h.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Japanese_k.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Korean.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Latin.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Russian.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_SerbianSH.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_SerbianSR.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Simplified_Chinese.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Thai.txt -text
|
||||
icu4j/tools/build/icu4j28.api.gz -text
|
||||
icu4j/tools/build/icu4j30.api.gz -text
|
||||
icu4j/tools/build/icu4j32.api.gz -text
|
||||
|
|
|
@ -1,218 +1,218 @@
|
|||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 1996-2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a port of the C++ class UConverterSelector.
|
||||
*
|
||||
* Methods related to serialization are not ported in this version. In addition,
|
||||
* the selectForUTF8 method is not going to be ported, as UTF8 is seldom used
|
||||
* in Java.
|
||||
*
|
||||
* @author Shaopeng Jia
|
||||
*/
|
||||
|
||||
package com.ibm.icu.charset;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.impl.IntTrie;
|
||||
import com.ibm.icu.impl.PropsVectors;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
/**
|
||||
* Charset Selector
|
||||
*
|
||||
* A charset selector is built with a list of charset names and given an input
|
||||
* CharSequence returns the list of names the corresponding charsets which can
|
||||
* convert the CharSequence.
|
||||
*
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public final class CharsetSelector {
|
||||
private IntTrie trie;
|
||||
private int[] pv; // table of bits
|
||||
private String[] encodings; // encodings users ask to use
|
||||
|
||||
private void generateSelectorData(PropsVectors pvec,
|
||||
UnicodeSet excludedCodePoints, int mappingTypes) {
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
|
||||
// set errorValue to all-ones
|
||||
for (int col = 0; col < columns; ++col) {
|
||||
pvec.setValue(PropsVectors.ERROR_VALUE_CP,
|
||||
PropsVectors.ERROR_VALUE_CP, col, ~0, ~0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < encodings.length; ++i) {
|
||||
Charset testCharset = CharsetICU.forNameICU(encodings[i]);
|
||||
UnicodeSet unicodePointSet = new UnicodeSet(); // empty set
|
||||
((CharsetICU) testCharset).getUnicodeSet(unicodePointSet,
|
||||
mappingTypes);
|
||||
int column = i / 32;
|
||||
int mask = 1 << (i % 32);
|
||||
// now iterate over intervals on set i
|
||||
int itemCount = unicodePointSet.getRangeCount();
|
||||
for (int j = 0; j < itemCount; ++j) {
|
||||
int startChar = unicodePointSet.getRangeStart(j);
|
||||
int endChar = unicodePointSet.getRangeEnd(j);
|
||||
pvec.setValue(startChar, endChar, column, ~0, mask);
|
||||
}
|
||||
}
|
||||
|
||||
// handle excluded encodings
|
||||
// Simply set their values to all 1's in the pvec
|
||||
if (!excludedCodePoints.isEmpty()) {
|
||||
int itemCount = excludedCodePoints.getRangeCount();
|
||||
for (int j = 0; j < itemCount; ++j) {
|
||||
int startChar = excludedCodePoints.getRangeStart(j);
|
||||
int endChar = excludedCodePoints.getRangeEnd(j);
|
||||
for (int col = 0; col < columns; col++) {
|
||||
pvec.setValue(startChar, endChar, col, ~0, ~0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trie = pvec.compactToTrieWithRowIndexes();
|
||||
pv = pvec.getCompactedArray();
|
||||
}
|
||||
|
||||
// internal function to intersect two sets of masks
|
||||
// returns whether the mask has reduced to all zeros. The
|
||||
// second set of mask consists of len elements in pv starting from
|
||||
// pvIndex
|
||||
private boolean intersectMasks(int[] dest, int pvIndex, int len) {
|
||||
int oredDest = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
oredDest |= (dest[i] &= pv[pvIndex + i]);
|
||||
}
|
||||
return oredDest == 0;
|
||||
}
|
||||
|
||||
// internal function
|
||||
private List<String> selectForMask(int[] mask) {
|
||||
// this is the context we will use. Store a table of indices to which
|
||||
// encodings are legit
|
||||
|
||||
Vector<String> result = new Vector<String>();
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
int numOnes = countOnes(mask, columns);
|
||||
|
||||
// now we know the exact space we need to index
|
||||
if (numOnes > 0) {
|
||||
int k = 0;
|
||||
for (int j = 0; j < columns; j++) {
|
||||
int v = mask[j];
|
||||
for (int i = 0; i < 32 && k < encodings.length; i++, k++) {
|
||||
if ((v & 1) != 0) {
|
||||
result.addElement(encodings[k]);
|
||||
}
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, index will remain NULL
|
||||
return result;
|
||||
}
|
||||
|
||||
// internal function to count how many 1's are there in a mask
|
||||
// algorithm taken from http://graphics.stanford.edu/~seander/bithacks.html
|
||||
private int countOnes(int[] mask, int len) {
|
||||
int totalOnes = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int ent = mask[i];
|
||||
for (; ent != 0; totalOnes++) {
|
||||
ent &= ent - 1; // clear the least significant bit set
|
||||
}
|
||||
}
|
||||
return totalOnes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a CharsetSelector from a list of charset names.
|
||||
*
|
||||
* @param charsetList
|
||||
* a list of charset names in the form of strings. If charsetList
|
||||
* is empty, a selector for all available charset is constructed.
|
||||
* @param excludedCodePoints
|
||||
* a set of code points to be excluded from consideration.
|
||||
* Excluded code points appearing in the input CharSequence do
|
||||
* not change the selection result. It could be empty when no
|
||||
* code point should be excluded.
|
||||
* @param mappingTypes
|
||||
* an int which determines whether to consider only roundtrip
|
||||
* mappings or also fallbacks, e.g. CharsetICU.ROUNDTRIP_SET. See
|
||||
* CharsetICU.java for the constants that are currently
|
||||
* supported.
|
||||
* @throws IllegalArgumentException
|
||||
* if the parameters is invalid.
|
||||
* @throws IllegalCharsetNameException
|
||||
* If the given charset name is illegal.
|
||||
* @throws UnsupportedCharsetException
|
||||
* If no support for the named charset is available in this
|
||||
* instance of the Java virtual machine.
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public CharsetSelector(List<String> charsetList, UnicodeSet excludedCodePoints,
|
||||
int mappingTypes) {
|
||||
if (mappingTypes != CharsetICU.ROUNDTRIP_AND_FALLBACK_SET
|
||||
&& mappingTypes != CharsetICU.ROUNDTRIP_SET) {
|
||||
throw new IllegalArgumentException("Unsupported mappingTypes");
|
||||
}
|
||||
|
||||
int encodingCount = charsetList.size();
|
||||
if (encodingCount > 0) {
|
||||
encodings = charsetList.toArray(new String[0]);
|
||||
} else {
|
||||
encodings = CharsetProviderICU.getAvailableNames();
|
||||
encodingCount = encodings.length;
|
||||
}
|
||||
|
||||
PropsVectors pvec = new PropsVectors((encodingCount + 31) / 32);
|
||||
generateSelectorData(pvec, excludedCodePoints, mappingTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select charsets that can map all characters in a CharSequence, ignoring
|
||||
* the excluded code points.
|
||||
*
|
||||
* @param unicodeText
|
||||
* a CharSequence. It could be empty.
|
||||
* @return a list that contains charset names in the form of strings. The
|
||||
* returned encoding names and their order will be the same as
|
||||
* supplied when building the selector.
|
||||
*
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public List<String> selectForString(CharSequence unicodeText) {
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
int[] mask = new int[columns];
|
||||
for (int i = 0; i < columns; i++) {
|
||||
mask[i] = - 1; // set each bit to 1
|
||||
// Note: All integers are signed in Java, assigning
|
||||
// 2 ^ 32 -1 to mask is wrong!
|
||||
}
|
||||
int index = 0;
|
||||
while (index < unicodeText.length()) {
|
||||
int c = UTF16.charAt(unicodeText, index);
|
||||
int pvIndex = trie.getCodePointValue(c);
|
||||
index += UTF16.getCharCount(c);
|
||||
if (intersectMasks(mask, pvIndex, columns)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return selectForMask(mask);
|
||||
}
|
||||
}
|
||||
/*
|
||||
******************************************************************************
|
||||
* Copyright (C) 1996-2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a port of the C++ class UConverterSelector.
|
||||
*
|
||||
* Methods related to serialization are not ported in this version. In addition,
|
||||
* the selectForUTF8 method is not going to be ported, as UTF8 is seldom used
|
||||
* in Java.
|
||||
*
|
||||
* @author Shaopeng Jia
|
||||
*/
|
||||
|
||||
package com.ibm.icu.charset;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.IllegalCharsetNameException;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.ibm.icu.impl.IntTrie;
|
||||
import com.ibm.icu.impl.PropsVectors;
|
||||
import com.ibm.icu.text.UTF16;
|
||||
import com.ibm.icu.text.UnicodeSet;
|
||||
|
||||
/**
|
||||
* Charset Selector
|
||||
*
|
||||
* A charset selector is built with a list of charset names and given an input
|
||||
* CharSequence returns the list of names the corresponding charsets which can
|
||||
* convert the CharSequence.
|
||||
*
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public final class CharsetSelector {
|
||||
private IntTrie trie;
|
||||
private int[] pv; // table of bits
|
||||
private String[] encodings; // encodings users ask to use
|
||||
|
||||
private void generateSelectorData(PropsVectors pvec,
|
||||
UnicodeSet excludedCodePoints, int mappingTypes) {
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
|
||||
// set errorValue to all-ones
|
||||
for (int col = 0; col < columns; ++col) {
|
||||
pvec.setValue(PropsVectors.ERROR_VALUE_CP,
|
||||
PropsVectors.ERROR_VALUE_CP, col, ~0, ~0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < encodings.length; ++i) {
|
||||
Charset testCharset = CharsetICU.forNameICU(encodings[i]);
|
||||
UnicodeSet unicodePointSet = new UnicodeSet(); // empty set
|
||||
((CharsetICU) testCharset).getUnicodeSet(unicodePointSet,
|
||||
mappingTypes);
|
||||
int column = i / 32;
|
||||
int mask = 1 << (i % 32);
|
||||
// now iterate over intervals on set i
|
||||
int itemCount = unicodePointSet.getRangeCount();
|
||||
for (int j = 0; j < itemCount; ++j) {
|
||||
int startChar = unicodePointSet.getRangeStart(j);
|
||||
int endChar = unicodePointSet.getRangeEnd(j);
|
||||
pvec.setValue(startChar, endChar, column, ~0, mask);
|
||||
}
|
||||
}
|
||||
|
||||
// handle excluded encodings
|
||||
// Simply set their values to all 1's in the pvec
|
||||
if (!excludedCodePoints.isEmpty()) {
|
||||
int itemCount = excludedCodePoints.getRangeCount();
|
||||
for (int j = 0; j < itemCount; ++j) {
|
||||
int startChar = excludedCodePoints.getRangeStart(j);
|
||||
int endChar = excludedCodePoints.getRangeEnd(j);
|
||||
for (int col = 0; col < columns; col++) {
|
||||
pvec.setValue(startChar, endChar, col, ~0, ~0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trie = pvec.compactToTrieWithRowIndexes();
|
||||
pv = pvec.getCompactedArray();
|
||||
}
|
||||
|
||||
// internal function to intersect two sets of masks
|
||||
// returns whether the mask has reduced to all zeros. The
|
||||
// second set of mask consists of len elements in pv starting from
|
||||
// pvIndex
|
||||
private boolean intersectMasks(int[] dest, int pvIndex, int len) {
|
||||
int oredDest = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
oredDest |= (dest[i] &= pv[pvIndex + i]);
|
||||
}
|
||||
return oredDest == 0;
|
||||
}
|
||||
|
||||
// internal function
|
||||
private List<String> selectForMask(int[] mask) {
|
||||
// this is the context we will use. Store a table of indices to which
|
||||
// encodings are legit
|
||||
|
||||
Vector<String> result = new Vector<String>();
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
int numOnes = countOnes(mask, columns);
|
||||
|
||||
// now we know the exact space we need to index
|
||||
if (numOnes > 0) {
|
||||
int k = 0;
|
||||
for (int j = 0; j < columns; j++) {
|
||||
int v = mask[j];
|
||||
for (int i = 0; i < 32 && k < encodings.length; i++, k++) {
|
||||
if ((v & 1) != 0) {
|
||||
result.addElement(encodings[k]);
|
||||
}
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// otherwise, index will remain NULL
|
||||
return result;
|
||||
}
|
||||
|
||||
// internal function to count how many 1's are there in a mask
|
||||
// algorithm taken from http://graphics.stanford.edu/~seander/bithacks.html
|
||||
private int countOnes(int[] mask, int len) {
|
||||
int totalOnes = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int ent = mask[i];
|
||||
for (; ent != 0; totalOnes++) {
|
||||
ent &= ent - 1; // clear the least significant bit set
|
||||
}
|
||||
}
|
||||
return totalOnes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a CharsetSelector from a list of charset names.
|
||||
*
|
||||
* @param charsetList
|
||||
* a list of charset names in the form of strings. If charsetList
|
||||
* is empty, a selector for all available charset is constructed.
|
||||
* @param excludedCodePoints
|
||||
* a set of code points to be excluded from consideration.
|
||||
* Excluded code points appearing in the input CharSequence do
|
||||
* not change the selection result. It could be empty when no
|
||||
* code point should be excluded.
|
||||
* @param mappingTypes
|
||||
* an int which determines whether to consider only roundtrip
|
||||
* mappings or also fallbacks, e.g. CharsetICU.ROUNDTRIP_SET. See
|
||||
* CharsetICU.java for the constants that are currently
|
||||
* supported.
|
||||
* @throws IllegalArgumentException
|
||||
* if the parameters is invalid.
|
||||
* @throws IllegalCharsetNameException
|
||||
* If the given charset name is illegal.
|
||||
* @throws UnsupportedCharsetException
|
||||
* If no support for the named charset is available in this
|
||||
* instance of the Java virtual machine.
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public CharsetSelector(List<String> charsetList, UnicodeSet excludedCodePoints,
|
||||
int mappingTypes) {
|
||||
if (mappingTypes != CharsetICU.ROUNDTRIP_AND_FALLBACK_SET
|
||||
&& mappingTypes != CharsetICU.ROUNDTRIP_SET) {
|
||||
throw new IllegalArgumentException("Unsupported mappingTypes");
|
||||
}
|
||||
|
||||
int encodingCount = charsetList.size();
|
||||
if (encodingCount > 0) {
|
||||
encodings = charsetList.toArray(new String[0]);
|
||||
} else {
|
||||
encodings = CharsetProviderICU.getAvailableNames();
|
||||
encodingCount = encodings.length;
|
||||
}
|
||||
|
||||
PropsVectors pvec = new PropsVectors((encodingCount + 31) / 32);
|
||||
generateSelectorData(pvec, excludedCodePoints, mappingTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select charsets that can map all characters in a CharSequence, ignoring
|
||||
* the excluded code points.
|
||||
*
|
||||
* @param unicodeText
|
||||
* a CharSequence. It could be empty.
|
||||
* @return a list that contains charset names in the form of strings. The
|
||||
* returned encoding names and their order will be the same as
|
||||
* supplied when building the selector.
|
||||
*
|
||||
* @draft ICU 4.2
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
public List<String> selectForString(CharSequence unicodeText) {
|
||||
int columns = (encodings.length + 31) / 32;
|
||||
int[] mask = new int[columns];
|
||||
for (int i = 0; i < columns; i++) {
|
||||
mask[i] = - 1; // set each bit to 1
|
||||
// Note: All integers are signed in Java, assigning
|
||||
// 2 ^ 32 -1 to mask is wrong!
|
||||
}
|
||||
int index = 0;
|
||||
while (index < unicodeText.length()) {
|
||||
int c = UTF16.charAt(unicodeText, index);
|
||||
int pvIndex = trie.getCodePointValue(c);
|
||||
index += UTF16.getCharCount(c);
|
||||
if (intersectMasks(mask, pvIndex, columns)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return selectForMask(mask);
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,248 +1,248 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.UResourceBundleIterator;
|
||||
|
||||
/**
|
||||
* <code>NumberingSystem</code> is the base class for all number
|
||||
* systems. This class provides the interface for setting different numbering
|
||||
* system types, whether it be a simple alternate digit system such as
|
||||
* Thai digits or Devanagari digits, or an algorithmic numbering system such
|
||||
* as Hebrew numbering or Chinese numbering.
|
||||
*
|
||||
* @author John Emmons
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
class NumberingSystem {
|
||||
|
||||
/**
|
||||
* Default constructor. Returns a numbering system that uses the Western decimal
|
||||
* digits 0 through 9.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public NumberingSystem() {
|
||||
radix = 10;
|
||||
algorithmic = false;
|
||||
desc = "0123456789";
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating a numbering system.
|
||||
* @param radix_in The radix for this numbering system. ICU currently
|
||||
* supports only numbering systems whose radix is 10.
|
||||
* @param isAlgorithmic_in Specifies whether the numbering system is algorithmic
|
||||
* (true) or numeric (false).
|
||||
* @param desc_in String used to describe the characteristics of the numbering
|
||||
* system. For numeric systems, this string contains the digits used by the
|
||||
* numbering system, in order, starting from zero. For algorithmic numbering
|
||||
* systems, the string contains the name of the RBNF ruleset in the locale's
|
||||
* NumberingSystemRules section that will be used to format numbers using
|
||||
* this numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(int radix_in, boolean isAlgorithmic_in, String desc_in ) {
|
||||
if ( radix_in < 2 ) {
|
||||
throw new IllegalArgumentException("Invalid radix for numbering system");
|
||||
}
|
||||
|
||||
if ( !isAlgorithmic_in ) {
|
||||
if ( desc_in.length() != radix_in || !isValidDigitString(desc_in)) {
|
||||
throw new IllegalArgumentException("Invalid digit string for numbering system");
|
||||
}
|
||||
}
|
||||
NumberingSystem ns = new NumberingSystem();
|
||||
ns.radix = radix_in;
|
||||
ns.algorithmic = isAlgorithmic_in;
|
||||
ns.desc = desc_in;
|
||||
return ns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the specified locale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(Locale inLocale) {
|
||||
return getInstance(ULocale.forLocale(inLocale));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the specified ULocale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(ULocale locale) {
|
||||
|
||||
String numbersKeyword = locale.getKeywordValue("numbers");
|
||||
if (numbersKeyword != null) {
|
||||
NumberingSystem ns = getInstanceByName(numbersKeyword);
|
||||
if ( ns != null ) {
|
||||
return ns;
|
||||
}
|
||||
}
|
||||
|
||||
String defaultNumberingSystem;
|
||||
|
||||
try {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
defaultNumberingSystem = rb.getString("defaultNumberingSystem");
|
||||
} catch (MissingResourceException ex) {
|
||||
return new NumberingSystem();
|
||||
}
|
||||
|
||||
NumberingSystem ns = getInstanceByName(defaultNumberingSystem);
|
||||
if ( ns != null ) {
|
||||
return ns;
|
||||
}
|
||||
|
||||
return new NumberingSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the default locale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance() {
|
||||
return getInstance(ULocale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numbering system from one of the predefined numbering systems
|
||||
* known to ICU. Numbering system names are based on the numbering systems
|
||||
* defined in CLDR. To get a list of available numbering systems, use the
|
||||
* getAvailableNames method.
|
||||
* @param name The name of the desired numbering system. Numbering system
|
||||
* names often correspond with the name of the script they are associated
|
||||
* with. For example, "thai" for Thai digits, "hebr" for Hebrew numerals.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstanceByName(String name) {
|
||||
int radix;
|
||||
boolean isAlgorithmic;
|
||||
String description;
|
||||
try {
|
||||
UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "numberingSystems");
|
||||
UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
|
||||
UResourceBundle nsTop = nsCurrent.get(name);
|
||||
|
||||
description = nsTop.getString("desc");
|
||||
UResourceBundle nsRadixBundle = nsTop.get("radix");
|
||||
UResourceBundle nsAlgBundle = nsTop.get("algorithmic");
|
||||
radix = nsRadixBundle.getInt();
|
||||
int algorithmic = nsAlgBundle.getInt();
|
||||
|
||||
isAlgorithmic = ( algorithmic == 1 );
|
||||
|
||||
} catch (MissingResourceException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInstance(radix,isAlgorithmic,description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string array containing a list of the names of numbering systems
|
||||
* currently known to ICU.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static String [] getAvailableNames() {
|
||||
|
||||
UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "numberingSystems");
|
||||
UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
|
||||
UResourceBundle temp;
|
||||
|
||||
String nsName;
|
||||
ArrayList<String> output = new ArrayList<String>();
|
||||
UResourceBundleIterator it = nsCurrent.getIterator();
|
||||
while (it.hasNext()) {
|
||||
temp = it.next();
|
||||
nsName = temp.getKey();
|
||||
output.add(nsName);
|
||||
}
|
||||
return output.toArray(new String[output.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to determine if a given digit string is valid for use as a
|
||||
* descriptor of a numeric ( non-algorithmic ) numbering system. In order for
|
||||
* a digit string to be valid, it must meet the following criteria:
|
||||
* 1. It must only contain characters that are decimal digits as defined by Unicode.
|
||||
* 2. It must contain characters that are contiguous code points.
|
||||
* 3. Digits must be in Unicode's basic multilingual plane.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static boolean isValidDigitString(String str) {
|
||||
|
||||
int c;
|
||||
int prev = 0;
|
||||
int i = 0;
|
||||
UCharacterIterator it = UCharacterIterator.getInstance(str);
|
||||
|
||||
it.setToStart();
|
||||
while ( (c = it.nextCodePoint()) != UCharacterIterator.DONE) {
|
||||
if ( UCharacter.digit(c) != i ) { // Digits outside the Unicode decimal digit class are not currently supported
|
||||
return false;
|
||||
}
|
||||
if ( prev != 0 && c != prev + 1 ) { // Non-contiguous digits are not currently supported
|
||||
return false;
|
||||
}
|
||||
if ( UCharacter.isSupplementary(c)) { // Digits outside the BMP are not currently supported
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
prev = c;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radix of the current numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public int getRadix() {
|
||||
return radix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description string of the current numbering system.
|
||||
* The description string describes the characteristics of the numbering
|
||||
* system. For numeric systems, this string contains the digits used by the
|
||||
* numbering system, in order, starting from zero. For algorithmic numbering
|
||||
* systems, the string contains the name of the RBNF ruleset in the locale's
|
||||
* NumberingSystemRules section that will be used to format numbers using
|
||||
* this numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numbering system's algorithmic status. If true,
|
||||
* the numbering system is algorithmic and uses an RBNF formatter to
|
||||
* format numerals. If false, the numbering system is numeric and
|
||||
* uses a fixed set of digits.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public boolean isAlgorithmic() {
|
||||
return algorithmic;
|
||||
}
|
||||
|
||||
|
||||
private String desc;
|
||||
private int radix;
|
||||
private boolean algorithmic;
|
||||
|
||||
}
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
import com.ibm.icu.impl.ICUResourceBundle;
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.util.ULocale;
|
||||
import com.ibm.icu.util.UResourceBundle;
|
||||
import com.ibm.icu.util.UResourceBundleIterator;
|
||||
|
||||
/**
|
||||
* <code>NumberingSystem</code> is the base class for all number
|
||||
* systems. This class provides the interface for setting different numbering
|
||||
* system types, whether it be a simple alternate digit system such as
|
||||
* Thai digits or Devanagari digits, or an algorithmic numbering system such
|
||||
* as Hebrew numbering or Chinese numbering.
|
||||
*
|
||||
* @author John Emmons
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
class NumberingSystem {
|
||||
|
||||
/**
|
||||
* Default constructor. Returns a numbering system that uses the Western decimal
|
||||
* digits 0 through 9.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public NumberingSystem() {
|
||||
radix = 10;
|
||||
algorithmic = false;
|
||||
desc = "0123456789";
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for creating a numbering system.
|
||||
* @param radix_in The radix for this numbering system. ICU currently
|
||||
* supports only numbering systems whose radix is 10.
|
||||
* @param isAlgorithmic_in Specifies whether the numbering system is algorithmic
|
||||
* (true) or numeric (false).
|
||||
* @param desc_in String used to describe the characteristics of the numbering
|
||||
* system. For numeric systems, this string contains the digits used by the
|
||||
* numbering system, in order, starting from zero. For algorithmic numbering
|
||||
* systems, the string contains the name of the RBNF ruleset in the locale's
|
||||
* NumberingSystemRules section that will be used to format numbers using
|
||||
* this numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(int radix_in, boolean isAlgorithmic_in, String desc_in ) {
|
||||
if ( radix_in < 2 ) {
|
||||
throw new IllegalArgumentException("Invalid radix for numbering system");
|
||||
}
|
||||
|
||||
if ( !isAlgorithmic_in ) {
|
||||
if ( desc_in.length() != radix_in || !isValidDigitString(desc_in)) {
|
||||
throw new IllegalArgumentException("Invalid digit string for numbering system");
|
||||
}
|
||||
}
|
||||
NumberingSystem ns = new NumberingSystem();
|
||||
ns.radix = radix_in;
|
||||
ns.algorithmic = isAlgorithmic_in;
|
||||
ns.desc = desc_in;
|
||||
return ns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the specified locale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(Locale inLocale) {
|
||||
return getInstance(ULocale.forLocale(inLocale));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the specified ULocale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance(ULocale locale) {
|
||||
|
||||
String numbersKeyword = locale.getKeywordValue("numbers");
|
||||
if (numbersKeyword != null) {
|
||||
NumberingSystem ns = getInstanceByName(numbersKeyword);
|
||||
if ( ns != null ) {
|
||||
return ns;
|
||||
}
|
||||
}
|
||||
|
||||
String defaultNumberingSystem;
|
||||
|
||||
try {
|
||||
ICUResourceBundle rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME,locale);
|
||||
defaultNumberingSystem = rb.getString("defaultNumberingSystem");
|
||||
} catch (MissingResourceException ex) {
|
||||
return new NumberingSystem();
|
||||
}
|
||||
|
||||
NumberingSystem ns = getInstanceByName(defaultNumberingSystem);
|
||||
if ( ns != null ) {
|
||||
return ns;
|
||||
}
|
||||
|
||||
return new NumberingSystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default numbering system for the default locale.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstance() {
|
||||
return getInstance(ULocale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a numbering system from one of the predefined numbering systems
|
||||
* known to ICU. Numbering system names are based on the numbering systems
|
||||
* defined in CLDR. To get a list of available numbering systems, use the
|
||||
* getAvailableNames method.
|
||||
* @param name The name of the desired numbering system. Numbering system
|
||||
* names often correspond with the name of the script they are associated
|
||||
* with. For example, "thai" for Thai digits, "hebr" for Hebrew numerals.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static NumberingSystem getInstanceByName(String name) {
|
||||
int radix;
|
||||
boolean isAlgorithmic;
|
||||
String description;
|
||||
try {
|
||||
UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "numberingSystems");
|
||||
UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
|
||||
UResourceBundle nsTop = nsCurrent.get(name);
|
||||
|
||||
description = nsTop.getString("desc");
|
||||
UResourceBundle nsRadixBundle = nsTop.get("radix");
|
||||
UResourceBundle nsAlgBundle = nsTop.get("algorithmic");
|
||||
radix = nsRadixBundle.getInt();
|
||||
int algorithmic = nsAlgBundle.getInt();
|
||||
|
||||
isAlgorithmic = ( algorithmic == 1 );
|
||||
|
||||
} catch (MissingResourceException ex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getInstance(radix,isAlgorithmic,description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string array containing a list of the names of numbering systems
|
||||
* currently known to ICU.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static String [] getAvailableNames() {
|
||||
|
||||
UResourceBundle numberingSystemsInfo = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, "numberingSystems");
|
||||
UResourceBundle nsCurrent = numberingSystemsInfo.get("numberingSystems");
|
||||
UResourceBundle temp;
|
||||
|
||||
String nsName;
|
||||
ArrayList<String> output = new ArrayList<String>();
|
||||
UResourceBundleIterator it = nsCurrent.getIterator();
|
||||
while (it.hasNext()) {
|
||||
temp = it.next();
|
||||
nsName = temp.getKey();
|
||||
output.add(nsName);
|
||||
}
|
||||
return output.toArray(new String[output.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to determine if a given digit string is valid for use as a
|
||||
* descriptor of a numeric ( non-algorithmic ) numbering system. In order for
|
||||
* a digit string to be valid, it must meet the following criteria:
|
||||
* 1. It must only contain characters that are decimal digits as defined by Unicode.
|
||||
* 2. It must contain characters that are contiguous code points.
|
||||
* 3. Digits must be in Unicode's basic multilingual plane.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public static boolean isValidDigitString(String str) {
|
||||
|
||||
int c;
|
||||
int prev = 0;
|
||||
int i = 0;
|
||||
UCharacterIterator it = UCharacterIterator.getInstance(str);
|
||||
|
||||
it.setToStart();
|
||||
while ( (c = it.nextCodePoint()) != UCharacterIterator.DONE) {
|
||||
if ( UCharacter.digit(c) != i ) { // Digits outside the Unicode decimal digit class are not currently supported
|
||||
return false;
|
||||
}
|
||||
if ( prev != 0 && c != prev + 1 ) { // Non-contiguous digits are not currently supported
|
||||
return false;
|
||||
}
|
||||
if ( UCharacter.isSupplementary(c)) { // Digits outside the BMP are not currently supported
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
prev = c;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the radix of the current numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public int getRadix() {
|
||||
return radix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the description string of the current numbering system.
|
||||
* The description string describes the characteristics of the numbering
|
||||
* system. For numeric systems, this string contains the digits used by the
|
||||
* numbering system, in order, starting from zero. For algorithmic numbering
|
||||
* systems, the string contains the name of the RBNF ruleset in the locale's
|
||||
* NumberingSystemRules section that will be used to format numbers using
|
||||
* this numbering system.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public String getDescription() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numbering system's algorithmic status. If true,
|
||||
* the numbering system is algorithmic and uses an RBNF formatter to
|
||||
* format numerals. If false, the numbering system is numeric and
|
||||
* uses a fixed set of digits.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
public boolean isAlgorithmic() {
|
||||
return algorithmic;
|
||||
}
|
||||
|
||||
|
||||
private String desc;
|
||||
private int radix;
|
||||
private boolean algorithmic;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue