mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-10 07:39:16 +00:00
ICU-19 Remove gnarliness of the UScript API
X-SVN-Rev: 6877
This commit is contained in:
parent
1775e1ab80
commit
182314101a
10 changed files with 574 additions and 482 deletions
|
@ -47,7 +47,7 @@ public class TestUScript extends TestFmwk{
|
|||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if( code[0] != expected[i]){
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class TestUScript extends TestFmwk{
|
|||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if( code[0] != expected[i]){
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package com.ibm.text.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import com.ibm.text.UScript;
|
||||
|
||||
public class LocaleScript extends ListResourceBundle {
|
||||
|
||||
|
@ -15,252 +16,308 @@ public class LocaleScript extends ListResourceBundle {
|
|||
}
|
||||
|
||||
private static final Object[][] localeScript = new Object[][] {
|
||||
{"af", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"af", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ar", new String[] {
|
||||
"ARAB",
|
||||
}
|
||||
{
|
||||
"ar", new int[] {
|
||||
UScript.ARABIC,
|
||||
}
|
||||
},
|
||||
{"be", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"be", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"bg", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"bg", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"ca", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ca", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"cs", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"cs", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"da", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"da", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"de", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"de", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"el", new String[] {
|
||||
"GREK",
|
||||
}
|
||||
{
|
||||
"el", new int[] {
|
||||
UScript.GREEK,
|
||||
}
|
||||
},
|
||||
{"en", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"en", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"eo", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"eo", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"es", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"es", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"et", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"et", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"eu", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"eu", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fa", new String[] {
|
||||
"ARAB",
|
||||
}
|
||||
{
|
||||
"fa", new int[] {
|
||||
UScript.ARABIC,
|
||||
}
|
||||
},
|
||||
{"fi", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fi", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fo", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fo", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ga", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ga", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"gl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"gl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"gv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"gv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"he", new String[] {
|
||||
"HEBR",
|
||||
}
|
||||
{
|
||||
"he", new int[] {
|
||||
UScript.HEBREW,
|
||||
}
|
||||
},
|
||||
{"hi", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"hi", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"hr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"hr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"hu", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"hu", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"id", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"id", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"is", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"is", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"it", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"it", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"iw", new String[] {
|
||||
"HEBR",
|
||||
}
|
||||
{
|
||||
"ja", new int[] {
|
||||
UScript.KATAKANA,
|
||||
UScript.HIRAGANA,
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"ja", new String[] {
|
||||
"KANA",
|
||||
"HIRA",
|
||||
"HANI"
|
||||
}
|
||||
{
|
||||
"kl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"kl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ko", new int[] {
|
||||
UScript.HANGUL,
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"ko", new String[] {
|
||||
"HANG",
|
||||
"HANI",
|
||||
}
|
||||
{
|
||||
"kok", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"kok", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"kw", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"kw", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"lt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"lt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"lv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"lv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"mk", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"mk", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"mr", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"mr", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"mt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"mt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nb", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nb", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nn", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nn", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"pl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"pl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"pt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"pt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ro", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ro", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ru", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"ru", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"sh", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sh", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sk", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sk", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sq", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sq", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sr", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"sr", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"sv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sw", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sw", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ta", new int[] {
|
||||
UScript.TAMIL,
|
||||
}
|
||||
},
|
||||
{"ta", new String[] {
|
||||
"TAML",
|
||||
}
|
||||
{
|
||||
"te", new int[] {
|
||||
UScript.TELUGU,
|
||||
}
|
||||
},
|
||||
{"te", new String[] {
|
||||
"TELU",
|
||||
}
|
||||
{
|
||||
"th", new int[] {
|
||||
UScript.THAI,
|
||||
}
|
||||
},
|
||||
{"th", new String[] {
|
||||
"THAI",
|
||||
}
|
||||
{
|
||||
"tr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"tr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"uk", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"uk", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"vi", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"vi", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"zh", new int[] {
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"zh", new String[] {
|
||||
"HANI",
|
||||
}
|
||||
},
|
||||
{"zh_TW", new String[] {
|
||||
"HANI",
|
||||
"BOPO",
|
||||
{
|
||||
"zh_TW", new int[]{
|
||||
UScript.HAN,
|
||||
UScript.BOPOMOFO,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -770,43 +770,37 @@ public final class UScript {
|
|||
|
||||
private static final String localeScript = "com.ibm.text.resources.LocaleScript";
|
||||
|
||||
private static int[] findCodeFromLocale(Locale locale)
|
||||
throws MissingResourceException{
|
||||
/**
|
||||
* Helper function to find the code from locale.
|
||||
* @param Locale the locale.
|
||||
* @exception MissingResourceException if LocaleScript cannot be opened
|
||||
*/
|
||||
private static int[] findCodeFromLocale(Locale locale){
|
||||
//TODO: Currently we use a hacked fallback mechanism.
|
||||
//Should be changed once ICU4J bundles locale data
|
||||
//with the distribution
|
||||
int[] code = new int[1];
|
||||
code[0] = INVALID_CODE;
|
||||
|
||||
ResourceBundle resB = ResourceBundle.getBundle(localeScript);
|
||||
String temp = locale.toString();
|
||||
while(true){
|
||||
try{
|
||||
String[] scriptArray = resB.getStringArray(temp);
|
||||
code = new int[scriptArray.length];
|
||||
for(int i= 0; i< scriptArray.length ;i++){
|
||||
int strIndex = findStringIndex(scriptAbbr,scriptArray[i]);
|
||||
|
||||
if(strIndex>=0 && strIndex < scriptAbbr.length){
|
||||
code[i] = scriptAbbrCodes[strIndex];
|
||||
}else{
|
||||
code[i] = INVALID_CODE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}catch(MissingResourceException e){
|
||||
|
||||
/* handle fallback */
|
||||
int index = temp.indexOf('_');
|
||||
if(index >0){
|
||||
temp = temp.substring(0,index);
|
||||
}else{
|
||||
int[] code = null;
|
||||
try{
|
||||
ResourceBundle resB = ResourceBundle.getBundle(localeScript);
|
||||
String temp = locale.toString();
|
||||
while(true){
|
||||
try{
|
||||
code =(int[])resB.getObject(temp);
|
||||
break;
|
||||
}catch(MissingResourceException e){
|
||||
/* handle fallback */
|
||||
int index = temp.indexOf('_');
|
||||
if(index >0){
|
||||
temp = temp.substring(0,index);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}catch( MissingResourceException ex){
|
||||
throw new InternalError();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -842,30 +836,28 @@ public final class UScript {
|
|||
|
||||
|
||||
/**
|
||||
* Gets a script code associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* @param locale Locale
|
||||
* @return The script code
|
||||
* @exception IllegalArgumentException, MissingResourceException
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @exception MissingResourceException
|
||||
* @draft
|
||||
*/
|
||||
public static final int[] getCode(Locale locale)
|
||||
throws IllegalArgumentException, MissingResourceException{
|
||||
throws MissingResourceException{
|
||||
return findCodeFromLocale(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a script code associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* @param nameOrAbbrOrLocale name of the script or ISO 15924 code or locale
|
||||
* @return The script code
|
||||
* @exception IllegalArgumentException, MissingResourceException
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @draft
|
||||
*/
|
||||
public static final int[] getCode(String nameOrAbbrOrLocale)
|
||||
throws IllegalArgumentException, MissingResourceException{
|
||||
public static final int[] getCode(String nameOrAbbrOrLocale){
|
||||
|
||||
int[] code = new int[1];
|
||||
code[0] = INVALID_CODE;
|
||||
|
@ -899,12 +891,11 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final int getScript(int codepoint)
|
||||
throws IllegalArgumentException{
|
||||
public static final int getScript(int codepoint){
|
||||
if (codepoint >= UCharacter.MIN_VALUE & codepoint <= UCharacter.MAX_VALUE) {
|
||||
return findScriptCode(codepoint);
|
||||
}else{
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException(Integer.toString(codepoint));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -916,8 +907,7 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final String getName(int scriptCode)
|
||||
throws IllegalArgumentException{
|
||||
public static final String getName(int scriptCode){
|
||||
int index = -1;
|
||||
if(scriptCode > CODE_LIMIT){
|
||||
throw new IllegalArgumentException(Integer.toString(scriptCode));
|
||||
|
@ -938,8 +928,7 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final String getShortName(int scriptCode)
|
||||
throws IllegalArgumentException{
|
||||
public static final String getShortName(int scriptCode){
|
||||
int index = -1;
|
||||
if(scriptCode > CODE_LIMIT){
|
||||
throw new IllegalArgumentException(Integer.toString(scriptCode));
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TestUScript extends TestFmwk{
|
|||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if( code[0] != expected[i]){
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ public class TestUScript extends TestFmwk{
|
|||
|
||||
for( ; i<testNames.length; i++){
|
||||
int[] code = UScript.getCode(testNames[i]);
|
||||
if( code[0] != expected[i]){
|
||||
if((code!=null) && (code[0] != expected[i])){
|
||||
logln("Error getting script code Got: " +code[0] + " Expected: " +expected[i] +" for name "+testNames[i]);
|
||||
numErrors++;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class TransliteratorRegistry {
|
|||
|
||||
// Canonicalize script name -or- do locale->script mapping
|
||||
int[] s = UScript.getCode(top);
|
||||
if (s[0] != UScript.INVALID_CODE) {
|
||||
if (s != null) {
|
||||
scriptName = UScript.getName(s[0]);
|
||||
// If the script name is the same as top then it's redundant
|
||||
if (scriptName.equalsIgnoreCase(top)) {
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/Attic/UnicodePropertySet.java,v $
|
||||
* $Date: 2001/11/07 19:27:09 $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2001/11/14 02:49:15 $
|
||||
* $Revision: 1.6 $
|
||||
**********************************************************************
|
||||
*/
|
||||
package com.ibm.text;
|
||||
|
@ -52,7 +52,7 @@ import com.ibm.util.Utility;
|
|||
* '+' indicates a supported property.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: UnicodePropertySet.java,v $ $Revision: 1.5 $ $Date: 2001/11/07 19:27:09 $
|
||||
* @version $RCSfile: UnicodePropertySet.java,v $ $Revision: 1.6 $ $Date: 2001/11/14 02:49:15 $
|
||||
*/
|
||||
class UnicodePropertySet {
|
||||
|
||||
|
@ -303,7 +303,7 @@ class UnicodePropertySet {
|
|||
*/
|
||||
private static UnicodeSet createScriptSet(String valueName) {
|
||||
int[] script = UScript.getCode(valueName);
|
||||
if (script[0] == UScript.INVALID_CODE) {
|
||||
if (script == null) {
|
||||
// Syntax error; unknown short name
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class TransliteratorRegistry {
|
|||
|
||||
// Canonicalize script name -or- do locale->script mapping
|
||||
int[] s = UScript.getCode(top);
|
||||
if (s[0] != UScript.INVALID_CODE) {
|
||||
if (s != null) {
|
||||
scriptName = UScript.getName(s[0]);
|
||||
// If the script name is the same as top then it's redundant
|
||||
if (scriptName.equalsIgnoreCase(top)) {
|
||||
|
|
|
@ -770,43 +770,37 @@ public final class UScript {
|
|||
|
||||
private static final String localeScript = "com.ibm.text.resources.LocaleScript";
|
||||
|
||||
private static int[] findCodeFromLocale(Locale locale)
|
||||
throws MissingResourceException{
|
||||
/**
|
||||
* Helper function to find the code from locale.
|
||||
* @param Locale the locale.
|
||||
* @exception MissingResourceException if LocaleScript cannot be opened
|
||||
*/
|
||||
private static int[] findCodeFromLocale(Locale locale){
|
||||
//TODO: Currently we use a hacked fallback mechanism.
|
||||
//Should be changed once ICU4J bundles locale data
|
||||
//with the distribution
|
||||
int[] code = new int[1];
|
||||
code[0] = INVALID_CODE;
|
||||
|
||||
ResourceBundle resB = ResourceBundle.getBundle(localeScript);
|
||||
String temp = locale.toString();
|
||||
while(true){
|
||||
try{
|
||||
String[] scriptArray = resB.getStringArray(temp);
|
||||
code = new int[scriptArray.length];
|
||||
for(int i= 0; i< scriptArray.length ;i++){
|
||||
int strIndex = findStringIndex(scriptAbbr,scriptArray[i]);
|
||||
|
||||
if(strIndex>=0 && strIndex < scriptAbbr.length){
|
||||
code[i] = scriptAbbrCodes[strIndex];
|
||||
}else{
|
||||
code[i] = INVALID_CODE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}catch(MissingResourceException e){
|
||||
|
||||
/* handle fallback */
|
||||
int index = temp.indexOf('_');
|
||||
if(index >0){
|
||||
temp = temp.substring(0,index);
|
||||
}else{
|
||||
int[] code = null;
|
||||
try{
|
||||
ResourceBundle resB = ResourceBundle.getBundle(localeScript);
|
||||
String temp = locale.toString();
|
||||
while(true){
|
||||
try{
|
||||
code =(int[])resB.getObject(temp);
|
||||
break;
|
||||
}catch(MissingResourceException e){
|
||||
/* handle fallback */
|
||||
int index = temp.indexOf('_');
|
||||
if(index >0){
|
||||
temp = temp.substring(0,index);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}catch( MissingResourceException ex){
|
||||
throw new InternalError();
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -842,30 +836,28 @@ public final class UScript {
|
|||
|
||||
|
||||
/**
|
||||
* Gets a script code associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* @param locale Locale
|
||||
* @return The script code
|
||||
* @exception IllegalArgumentException, MissingResourceException
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @exception MissingResourceException
|
||||
* @draft
|
||||
*/
|
||||
public static final int[] getCode(Locale locale)
|
||||
throws IllegalArgumentException, MissingResourceException{
|
||||
throws MissingResourceException{
|
||||
return findCodeFromLocale(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a script code associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Gets a script codes associated with the given locale or ISO 15924 abbreviation or name.
|
||||
* Returns MALAYAM given "Malayam" OR "Mlym".
|
||||
* Returns LATIN given "en" OR "en_US"
|
||||
* @param nameOrAbbrOrLocale name of the script or ISO 15924 code or locale
|
||||
* @return The script code
|
||||
* @exception IllegalArgumentException, MissingResourceException
|
||||
* @return The script codes array. null if the the code cannot be found.
|
||||
* @draft
|
||||
*/
|
||||
public static final int[] getCode(String nameOrAbbrOrLocale)
|
||||
throws IllegalArgumentException, MissingResourceException{
|
||||
public static final int[] getCode(String nameOrAbbrOrLocale){
|
||||
|
||||
int[] code = new int[1];
|
||||
code[0] = INVALID_CODE;
|
||||
|
@ -899,12 +891,11 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final int getScript(int codepoint)
|
||||
throws IllegalArgumentException{
|
||||
public static final int getScript(int codepoint){
|
||||
if (codepoint >= UCharacter.MIN_VALUE & codepoint <= UCharacter.MAX_VALUE) {
|
||||
return findScriptCode(codepoint);
|
||||
}else{
|
||||
throw new IllegalArgumentException();
|
||||
throw new IllegalArgumentException(Integer.toString(codepoint));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -916,8 +907,7 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final String getName(int scriptCode)
|
||||
throws IllegalArgumentException{
|
||||
public static final String getName(int scriptCode){
|
||||
int index = -1;
|
||||
if(scriptCode > CODE_LIMIT){
|
||||
throw new IllegalArgumentException(Integer.toString(scriptCode));
|
||||
|
@ -938,8 +928,7 @@ public final class UScript {
|
|||
* @exception IllegalArgumentException
|
||||
* @draft
|
||||
*/
|
||||
public static final String getShortName(int scriptCode)
|
||||
throws IllegalArgumentException{
|
||||
public static final String getShortName(int scriptCode){
|
||||
int index = -1;
|
||||
if(scriptCode > CODE_LIMIT){
|
||||
throw new IllegalArgumentException(Integer.toString(scriptCode));
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* Corporation and others. All Rights Reserved.
|
||||
**********************************************************************
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/text/Attic/UnicodePropertySet.java,v $
|
||||
* $Date: 2001/11/07 19:27:09 $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2001/11/14 02:49:15 $
|
||||
* $Revision: 1.6 $
|
||||
**********************************************************************
|
||||
*/
|
||||
package com.ibm.text;
|
||||
|
@ -52,7 +52,7 @@ import com.ibm.util.Utility;
|
|||
* '+' indicates a supported property.
|
||||
*
|
||||
* @author Alan Liu
|
||||
* @version $RCSfile: UnicodePropertySet.java,v $ $Revision: 1.5 $ $Date: 2001/11/07 19:27:09 $
|
||||
* @version $RCSfile: UnicodePropertySet.java,v $ $Revision: 1.6 $ $Date: 2001/11/14 02:49:15 $
|
||||
*/
|
||||
class UnicodePropertySet {
|
||||
|
||||
|
@ -303,7 +303,7 @@ class UnicodePropertySet {
|
|||
*/
|
||||
private static UnicodeSet createScriptSet(String valueName) {
|
||||
int[] script = UScript.getCode(valueName);
|
||||
if (script[0] == UScript.INVALID_CODE) {
|
||||
if (script == null) {
|
||||
// Syntax error; unknown short name
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package com.ibm.text.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import com.ibm.text.UScript;
|
||||
|
||||
public class LocaleScript extends ListResourceBundle {
|
||||
|
||||
|
@ -15,252 +16,308 @@ public class LocaleScript extends ListResourceBundle {
|
|||
}
|
||||
|
||||
private static final Object[][] localeScript = new Object[][] {
|
||||
{"af", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"af", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ar", new String[] {
|
||||
"ARAB",
|
||||
}
|
||||
{
|
||||
"ar", new int[] {
|
||||
UScript.ARABIC,
|
||||
}
|
||||
},
|
||||
{"be", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"be", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"bg", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"bg", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"ca", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ca", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"cs", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"cs", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"da", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"da", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"de", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"de", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"el", new String[] {
|
||||
"GREK",
|
||||
}
|
||||
{
|
||||
"el", new int[] {
|
||||
UScript.GREEK,
|
||||
}
|
||||
},
|
||||
{"en", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"en", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"eo", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"eo", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"es", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"es", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"et", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"et", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"eu", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"eu", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fa", new String[] {
|
||||
"ARAB",
|
||||
}
|
||||
{
|
||||
"fa", new int[] {
|
||||
UScript.ARABIC,
|
||||
}
|
||||
},
|
||||
{"fi", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fi", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fo", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fo", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"fr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"fr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ga", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ga", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"gl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"gl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"gv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"gv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"he", new String[] {
|
||||
"HEBR",
|
||||
}
|
||||
{
|
||||
"he", new int[] {
|
||||
UScript.HEBREW,
|
||||
}
|
||||
},
|
||||
{"hi", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"hi", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"hr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"hr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"hu", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"hu", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"id", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"id", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"is", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"is", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"it", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"it", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"iw", new String[] {
|
||||
"HEBR",
|
||||
}
|
||||
{
|
||||
"ja", new int[] {
|
||||
UScript.KATAKANA,
|
||||
UScript.HIRAGANA,
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"ja", new String[] {
|
||||
"KANA",
|
||||
"HIRA",
|
||||
"HANI"
|
||||
}
|
||||
{
|
||||
"kl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"kl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ko", new int[] {
|
||||
UScript.HANGUL,
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"ko", new String[] {
|
||||
"HANG",
|
||||
"HANI",
|
||||
}
|
||||
{
|
||||
"kok", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"kok", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"kw", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"kw", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"lt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"lt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"lv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"lv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"mk", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"mk", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"mr", new int[] {
|
||||
UScript.DEVANAGARI,
|
||||
}
|
||||
},
|
||||
{"mr", new String[] {
|
||||
"DEVA",
|
||||
}
|
||||
{
|
||||
"mt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"mt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nb", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nb", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"nn", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"nn", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"pl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"pl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"pt", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"pt", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ro", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"ro", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ru", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"ru", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"sh", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sh", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sk", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sk", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sl", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sl", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sq", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sq", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sr", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"sr", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"sv", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sv", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"sw", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"sw", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"ta", new int[] {
|
||||
UScript.TAMIL,
|
||||
}
|
||||
},
|
||||
{"ta", new String[] {
|
||||
"TAML",
|
||||
}
|
||||
{
|
||||
"te", new int[] {
|
||||
UScript.TELUGU,
|
||||
}
|
||||
},
|
||||
{"te", new String[] {
|
||||
"TELU",
|
||||
}
|
||||
{
|
||||
"th", new int[] {
|
||||
UScript.THAI,
|
||||
}
|
||||
},
|
||||
{"th", new String[] {
|
||||
"THAI",
|
||||
}
|
||||
{
|
||||
"tr", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"tr", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"uk", new int[] {
|
||||
UScript.CYRILLIC,
|
||||
}
|
||||
},
|
||||
{"uk", new String[] {
|
||||
"CYRL",
|
||||
}
|
||||
{
|
||||
"vi", new int[] {
|
||||
UScript.LATIN,
|
||||
}
|
||||
},
|
||||
{"vi", new String[] {
|
||||
"LATN",
|
||||
}
|
||||
{
|
||||
"zh", new int[] {
|
||||
UScript.HAN,
|
||||
}
|
||||
},
|
||||
{"zh", new String[] {
|
||||
"HANI",
|
||||
}
|
||||
},
|
||||
{"zh_TW", new String[] {
|
||||
"HANI",
|
||||
"BOPO",
|
||||
{
|
||||
"zh_TW", new int[]{
|
||||
UScript.HAN,
|
||||
UScript.BOPOMOFO,
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue