1 7 8 package com.ibm.icu.lang; 9 10 import com.ibm.icu.impl.ICUResourceBundle; 11 import com.ibm.icu.impl.UCharacterProperty; 12 import com.ibm.icu.util.ULocale; 13 import com.ibm.icu.util.UResourceBundle; 14 15 import java.util.Locale ; 16 import java.util.MissingResourceException ; 17 18 25 public final class UScript { 26 29 private static final String copyrightNotice 30 = "Copyright \u00a92001 IBM Corp. All rights reserved."; 31 32 36 public static final int INVALID_CODE = -1; 37 41 public static final int COMMON = 0; 42 46 public static final int INHERITED = 1; 47 51 public static final int ARABIC = 2; 52 56 public static final int ARMENIAN = 3; 57 61 public static final int BENGALI = 4; 62 66 public static final int BOPOMOFO = 5; 67 71 public static final int CHEROKEE = 6; 72 76 public static final int COPTIC = 7; 77 81 public static final int CYRILLIC = 8; 82 86 public static final int DESERET = 9; 87 91 public static final int DEVANAGARI = 10; 92 96 public static final int ETHIOPIC = 11; 97 101 public static final int GEORGIAN = 12; 102 106 public static final int GOTHIC = 13; 107 111 public static final int GREEK = 14; 112 116 public static final int GUJARATI = 15; 117 121 public static final int GURMUKHI = 16; 122 126 public static final int HAN = 17; 127 131 public static final int HANGUL = 18; 132 136 public static final int HEBREW = 19; 137 141 public static final int HIRAGANA = 20; 142 146 public static final int KANNADA = 21; 147 151 public static final int KATAKANA = 22; 152 156 public static final int KHMER = 23; 157 161 public static final int LAO = 24; 162 166 public static final int LATIN = 25; 167 171 public static final int MALAYALAM = 26; 172 176 public static final int MONGOLIAN = 27; 177 181 public static final int MYANMAR = 28; 182 186 public static final int OGHAM = 29; 187 191 public static final int OLD_ITALIC = 30; 192 196 public static final int ORIYA = 31; 197 201 public static final int RUNIC = 32; 202 206 public static final int SINHALA = 33; 207 211 public static final int SYRIAC = 34; 212 216 public static final int TAMIL = 35; 217 221 public static final int TELUGU = 36; 222 226 public static final int THAANA = 37; 227 231 public static final int THAI = 38; 232 236 public static final int TIBETAN = 39; 237 241 public static final int CANADIAN_ABORIGINAL = 40; 242 246 public static final int UCAS = CANADIAN_ABORIGINAL; 247 251 public static final int YI = 41; 252 256 public static final int TAGALOG = 42; 257 261 public static final int HANUNOO = 43; 262 266 public static final int BUHID = 44; 267 271 public static final int TAGBANWA = 45; 272 278 public static final int BRAILLE = 46; 279 285 public static final int CYPRIOT = 47; 286 292 public static final int LIMBU = 48; 293 299 public static final int LINEAR_B = 49; 300 306 public static final int OSMANYA = 50; 307 313 public static final int SHAVIAN = 51; 314 320 public static final int TAI_LE = 52; 321 327 public static final int UGARITIC = 53; 328 332 public static final int KATAKANA_OR_HIRAGANA = 54; 333 334 335 336 341 public static final int BUGINESE = 55; 342 347 public static final int GLAGOLITIC = 56; 348 353 public static final int KHAROSHTHI = 57; 354 359 public static final int SYLOTI_NAGRI = 58; 360 365 public static final int NEW_TAI_LUE = 59; 366 371 public static final int TIFINAGH = 60; 372 377 public static final int OLD_PERSIAN = 61; 378 379 380 385 public static final int BALINESE = 62; 386 391 public static final int BATAK = 63; 392 397 public static final int BLISSYMBOLS = 64; 398 403 public static final int BRAHMI = 65; 404 409 public static final int CHAM = 66; 410 415 public static final int CIRTH = 67; 416 421 public static final int OLD_CHURCH_SLAVONIC_CYRILLIC = 68; 422 427 public static final int DEMOTIC_EGYPTIAN = 69; 428 433 public static final int HIERATIC_EGYPTIAN = 70; 434 439 public static final int EGYPTIAN_HIEROGLYPHS = 71; 440 445 public static final int KHUTSURI = 72; 446 451 public static final int SIMPLIFIED_HAN = 73; 452 457 public static final int TRADITIONAL_HAN = 74; 458 463 public static final int PAHAWH_HMONG = 75; 464 469 public static final int OLD_HUNGARIAN = 76; 470 475 public static final int HARAPPAN_INDUS = 77; 476 481 public static final int JAVANESE = 78; 482 487 public static final int KAYAH_LI = 79; 488 493 public static final int LATIN_FRAKTUR = 80; 494 499 public static final int LATIN_GAELIC = 81; 500 505 public static final int LEPCHA = 82; 506 511 public static final int LINEAR_A = 83; 512 517 public static final int MANDAEAN = 84; 518 523 public static final int MAYAN_HIEROGLYPHS = 85; 524 529 public static final int MEROITIC = 86; 530 535 public static final int NKO = 87; 536 541 public static final int ORKHON = 88; 542 547 public static final int OLD_PERMIC = 89; 548 553 public static final int PHAGS_PA = 90; 554 559 public static final int PHOENICIAN = 91; 560 565 public static final int PHONETIC_POLLARD = 92; 566 571 public static final int RONGORONGO = 93; 572 577 public static final int SARATI = 94; 578 583 public static final int ESTRANGELO_SYRIAC = 95; 584 589 public static final int WESTERN_SYRIAC = 96; 590 595 public static final int EASTERN_SYRIAC = 97; 596 601 public static final int TENGWAR = 98; 602 607 public static final int VAI = 99; 608 613 public static final int VISIBLE_SPEECH = 100; 614 619 public static final int CUNEIFORM = 101; 620 625 public static final int UNWRITTEN_LANGUAGES = 102; 626 631 public static final int UNKNOWN = 103; 632 633 634 635 639 public static final int CODE_LIMIT = 104; 640 641 private static final int SCRIPT_MASK = 0x0000007f; 642 private static final UCharacterProperty prop= UCharacterProperty.getInstance(); 643 private static final String kLocaleScript = "LocaleScript"; 644 645 650 private static int[] findCodeFromLocale(ULocale locale) { 651 ICUResourceBundle rb; 652 try { 653 rb = (ICUResourceBundle)UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, locale); 654 } 655 catch (MissingResourceException e) { 656 return null; 657 } 658 659 if(rb.getLoadingStatus()==ICUResourceBundle.FROM_DEFAULT && ! locale.equals(ULocale.getDefault())){ 665 return null; 666 } 667 ICUResourceBundle sub = rb.get(kLocaleScript); 668 669 int[] result = new int[sub.getSize()]; 670 int w = 0; 671 for (int i = 0; i < result.length; ++i) { 672 int code = UCharacter.getPropertyValueEnum(UProperty.SCRIPT, 673 sub.getString(i)); 674 result[w++] = code; 675 676 } 677 678 if (w < result.length) { 679 throw new IllegalStateException ("bad locale data, listed " + 680 result.length + " scripts but found only " + w); 681 } 682 683 return result; 684 } 685 686 694 public static final int[] getCode(Locale locale){ 695 return findCodeFromLocale(ULocale.forLocale(locale)); 696 } 697 705 public static final int[] getCode(ULocale locale){ 706 return findCodeFromLocale(locale); 707 } 708 721 public static final int[] getCode(String nameOrAbbrOrLocale){ 722 try { 723 return new int[] { 724 UCharacter.getPropertyValueEnum(UProperty.SCRIPT, 725 nameOrAbbrOrLocale) 726 }; 727 } catch (IllegalArgumentException e) { 728 return findCodeFromLocale(new ULocale(nameOrAbbrOrLocale)); 729 } 730 } 731 732 741 public static final int getCodeFromName(String nameOrAbbr) { 742 try { 743 return UCharacter.getPropertyValueEnum(UProperty.SCRIPT, 744 nameOrAbbr); 745 } catch (IllegalArgumentException e) { 746 return INVALID_CODE; 747 } 748 } 749 750 757 public static final int getScript(int codepoint){ 758 if (codepoint >= UCharacter.MIN_VALUE & codepoint <= UCharacter.MAX_VALUE) { 759 return (prop.getAdditional(codepoint,0) & SCRIPT_MASK); 760 }else{ 761 throw new IllegalArgumentException (Integer.toString(codepoint)); 762 } 763 } 764 765 772 public static final String getName(int scriptCode){ 773 return UCharacter.getPropertyValueName(UProperty.SCRIPT, 774 scriptCode, 775 UProperty.NameChoice.LONG); 776 } 777 778 785 public static final String getShortName(int scriptCode){ 786 return UCharacter.getPropertyValueName(UProperty.SCRIPT, 787 scriptCode, 788 UProperty.NameChoice.SHORT); 789 } 790 794 private UScript(){} 795 } 797 798 | Popular Tags |