1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283
|
/* java.lang.Character
Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package java.lang;
import java.util.*;
import java.io.*;
import gnu.java.lang.ClassLoaderHelper;
/**
* Wrapper class for the primitive char data type. In addition,
* this class allows one to retrieve property information and
* perform transformations on the 38,000+ characters in the
* Unicode Standard, Version 2. java.lang.Character is designed
* to be very dynamic, and as such, it retrieves information on
* the Unicode character set from a separate database, which
* can be easily upgraded.<br>
* <br>
* For predicates, boundaries are used to describe
* the set of characters for which the method will return true.
* This syntax uses fairly normal regular expression notation.
* See 5.13 of the Unicode Standard, Version 2.0, for the
* boundary specification.<br>
* <br>
* See http://www.unicode.org for more information on the Unicode Standard.
*
* @author Paul N. Fisher
* @since JDK1.0
*/
public final class Character implements Serializable, Comparable
{
/**
* Constants for character blocks.
* All character blocks are part of the Unicode 2 standard, unless
* otherwise noted.
*/
public static class Subset {
private char start;
private char end;
private static final int NUM_SUBSETS = 66;
private static final Subset sets[] = new Subset[NUM_SUBSETS];
/**
* Returns the Unicode character block which a character belongs to.
*/
private static Subset getBlock(char ch) {
// do a simple binary search for the correct block
int low = 0; int hi = sets.length-1; int mid = 0;
while (low <= hi) {
mid = (low + hi) >> 1;
Subset b = sets[mid];
if (ch < b.start)
hi = mid - 1;
else if (ch > b.end)
low = mid + 1;
else return b;
}
return null;
}
/**
* Constructor for strictly defined normative blocks
*/
private Subset(int num, char start, char end) {
this.start = start;
this.end = end;
sets[num] = this;
}
/**
* Constructor for strictly defined blocks.
*/
private Subset(char start, char end) {
this.start = start;
this.end = end;
}
/**
* Constructor for loosely defined CJK blocks
*/
private Subset() { }
/**
* U+0000 - U+007F
*/
public final static Subset BASIC_LATIN = new Subset(0, '\u0000', '\u007F');
/**
* U+0080 - U+00FF
*/
public final static Subset LATIN_1_SUPPLEMENT = new Subset(1, '\u0080', '\u00FF');
/**
* U+0100 - U+017F
*/
public final static Subset LATIN_EXTENDED_A = new Subset(2, '\u0100', '\u017F');
/**
* U+0180 - U+024F
*/
public final static Subset LATIN_EXTENDED_B = new Subset(3, '\u0180', '\u024F');
/**
* U+0250 - U+02AF
*/
public final static Subset IPA_EXTENSIONS = new Subset(4,'\u0250', '\u02AF');
/**
* U+02B0 - U+02FF
*/
public final static Subset SPACING_MODIFIER_LETTERS = new Subset(5, '\u02B0', '\u02FF');
/**
* U+0300 - U+036F
*/
public final static Subset COMBINING_DIACRITICAL_MARKS = new Subset(6, '\u0300', '\u036F');
/**
* U+0370 - U+03FF
*/
public final static Subset GREEK = new Subset(7, '\u0370', '\u03FF');
/**
* U+0400 - U+04FF
*/
public final static Subset CYRILLIC = new Subset(8, '\u0400', '\u04FF');
/**
* U+0530 - U+058F
*/
public final static Subset ARMENIAN = new Subset(9, '\u0530', '\u058F');
/**
* U+0590 - U+05FF
*/
public final static Subset HEBREW = new Subset(10, '\u0590', '\u05FF');
/**
* U+0600 - U+06FF
*/
public final static Subset ARABIC = new Subset(11, '\u0600', '\u06FF');
/**
* U+0900 - U+097F
*/
public final static Subset DEVANAGARI = new Subset(12, '\u0900', '\u097F');
/**
* U+0980 - U+09FF
*/
public final static Subset BENGALI = new Subset(13, '\u0980', '\u09FF');
/**
* U+0A00 - U+0A7F
*/
public final static Subset GURMUKHI = new Subset(14, '\u0A00', '\u0A7F');
/**
* U+0A80 - U+0AFF
*/
public final static Subset GUJARATI = new Subset(15, '\u0A80', '\u0AFF');
/**
* U+0B00 - U+0B7F
*/
public final static Subset ORIYA = new Subset(16, '\u0B00', '\u0B7F');
/**
* U+0B80 - U+0BFF
*/
public final static Subset TAMIL = new Subset(17, '\u0B80', '\u0BFF');
/**
* U+0C00 - U+0C7F
*/
public final static Subset TELUGU = new Subset(18, '\u0C00', '\u0C7F');
/**
* U+0C80 - U+0CFF
*/
public final static Subset KANNADA = new Subset(19, '\u0C80', '\u0CFF');
/**
* U+0D00 - U+0D7F
*/
public final static Subset MALAYALAM = new Subset(20, '\u0D00', '\u0D7F');
/**
* U+0E00 - U+0E7F
*/
public final static Subset THAI = new Subset(21, '\u0E00', '\u0E7F');
/**
* U+0E80 - U+0EFF
*/
public final static Subset LAO = new Subset(22, '\u0E80', '\u0EFF');
/**
* U+0F00 - U+0FBF
*/
public final static Subset TIBETAN = new Subset(23, '\u0F00', '\u0FBF');
/**
* U+10A0 - U+10FF
*/
public final static Subset GEORGIAN = new Subset(24, '\u10A0', '\u10FF');
/**
* U+1100 - U+11FF
*/
public final static Subset HANGUL_JAMO = new Subset(25, '\u1100', '\u11FF');
/**
* U+1E00 - U+1EFF
*/
public final static Subset LATIN_EXTENDED_ADDITIONAL = new Subset(26, '\u1E00', '\u1EFF');
/**
* U+1F00 - U+1FFF
*/
public final static Subset GREEK_EXTENDED = new Subset(27, '\u1F00', '\u1FFF');
/**
* U+2000 - U+206F
*/
public final static Subset GENERAL_PUNCTUATION = new Subset(28, '\u2000', '\u206F');
/**
* U+2070 - U+209F
*/
public final static Subset SUPERSCRIPTS_AND_SUBSCRIPTS = new Subset(29, '\u2070', '\u209F');
/**
* U+20A0 - U+20CF
*/
public final static Subset CURRENCY_SYMBOLS = new Subset(30, '\u20A0', '\u20CF');
/**
* U+20D0 - U+20FF
*/
public final static Subset COMBINING_MARKS_FOR_SYMBOLS = new Subset(31, '\u20D0', '\u20FF');
/**
* U+2100 - U+214F
*/
public final static Subset LETTERLIKE_SYMBOLS = new Subset(32, '\u2100', '\u214F');
/**
* U+2150 - U+218F
*/
public final static Subset NUMBER_FORMS = new Subset(33, '\u2150', '\u218F');
/**
* U+2190 - U+21FF
*/
public final static Subset ARROWS = new Subset(34, '\u2190', '\u21FF');
/**
* U+2200 - U+22FF
*/
public final static Subset MATHEMATICAL_OPERATORS = new Subset(35, '\u2200', '\u22FF');
/**
* U+2300 - U+23FF
*/
public final static Subset MISCELLANEOUS_TECHNICAL = new Subset(36, '\u2300', '\u23FF');
/**
* U+2400 - U+243F
*/
public final static Subset CONTROL_PICTURES = new Subset(37, '\u2400', '\u243F');
/**
* U+2440 - U+245F
*/
public final static Subset OPTICAL_CHARACTER_RECOGNITION = new Subset(38, '\u2440', '\u245F');
/**
* U+2460 - U+24FF
*/
public final static Subset ENCLOSED_ALPHANUMERICS = new Subset(39, '\u2460', '\u24FF');
/**
* U+2500 - U+257F
*/
public final static Subset BOX_DRAWING = new Subset(40, '\u2500', '\u257F');
/**
* U+2580 - U+259F
*/
public final static Subset BLOCK_ELEMENTS = new Subset(41, '\u2580', '\u259F');
/**
* U+25A0 - U+25FF
*/
public final static Subset GEOMETRIC_SHAPES = new Subset(42, '\u25A0', '\u25FF');
/**
* U+2600 - U+26FF
*/
public final static Subset MISCELLANEOUS_SYMBOLS = new Subset(43, '\u2600', '\u26FF');
/**
* U+2700 - U+27BF
*/
public final static Subset DINGBATS = new Subset(44, '\u2700', '\u27BF');
/**
* U+3000 - U+303F
*/
public final static Subset CJK_SYMBOLS_AND_PUNCTUATION = new Subset(45, '\u3000', '\u303F');
/**
* U+3040 - U+309F
*/
public final static Subset HIRAGANA = new Subset(46, '\u3040', '\u309F');
/**
* U+30A0 - U+30FF
*/
public final static Subset KATAKANA = new Subset(47, '\u30A0', '\u30FF');
/**
* U+3100 - U+312F
*/
public final static Subset BOPOMOFO = new Subset(48, '\u3100', '\u312F');
/**
* U+3130 - U+318F
*/
public final static Subset HANGUL_COMPATIBILITY_JAMO = new Subset(49, '\u3130', '\u318F');
/**
* U+3190 - U+319F
*/
public final static Subset KANBUN = new Subset(50, '\u3190', '\u319F');
/**
* U+3200 - U+32FF
*/
public final static Subset ENCLOSED_CJK_LETTERS_AND_MONTHS = new Subset(51, '\u3200', '\u32FF');
/**
* U+3300 - U+33FF
*/
public final static Subset CJK_COMPATIBILITY = new Subset(52, '\u3300', '\u33FF');
/**
* U+4E00 - U+9FFF
*/
public final static Subset CJK_UNIFIED_IDEOGRAPHS = new Subset(53, '\u4E00', '\u9FFF');
/**
* U+AC00 - U+D7A3
*/
public final static Subset HANGUL_SYLLABLES = new Subset(54, '\uAC00', '\uD7A3');
/**
* SURROGATES combines the following 3 Unicode character blocks:<br>
* High Surrogates: U+D800 - U+DB7F<br>
* High Private Use Surrogates: U+DB80 - U+DBFF<br>
* Low Surrogates: U+DC00 - U+DFFF
*/
public final static Subset SURROGATES = new Subset(55, '\uD800', '\uDFFF');
/**
* U+E000 - U+F8FF
*/
public final static Subset PRIVATE_USE = new Subset(56, '\uE000', '\uF8FF');
/**
* U+F900 - U+FAFF
*/
public final static Subset CJK_COMPATIBILITY_IDEOGRAPHS = new Subset(57, '\uF900', '\uFAFF');
/**
* U+FB00 - U+FB4F
*/
public final static Subset ALPHABETIC_PRESENTATION_FORMS = new Subset(58, '\uFB00', '\uFB4F');
/**
* U+FB50 - U+FDFF
*/
public final static Subset ARABIC_PRESENTATION_FORMS_A = new Subset(59, '\uFB50', '\uFDFF');
/**
* U+FE20 - U+FE2F
*/
public final static Subset COMBINING_HALF_MARKS = new Subset(60, '\uFE20', '\uFE2F');
/**
* U+FE30 - U+FE4F
*/
public final static Subset CJK_COMPATIBILITY_FORMS = new Subset(61, '\uFE30', '\uFE4F');
/**
* U+FE50 - U+FE6F
*/
public final static Subset SMALL_FORM_VARIANTS = new Subset(62, '\uFE50', '\uFE6F');
/**
* U+FE70 - U+FEFF
*/
public final static Subset ARABIC_PRESENTATION_FORMS_B = new Subset(63, '\uFE70', '\uFEFF');
/**
* U+FF00 - U+FFEF
*/
public final static Subset HALFWIDTH_AND_FULLWIDTH_FORMS = new Subset(64, '\uFF00', '\uFFEF');
/**
* SPECIALS combine the following two Unicode character blocks:<br>
* SPECIALS: U+FEFF - U+FEFF<br>
* SPECIALS: U+FFF0 - U+FFFF
*/
public final static Subset SPECIALS = new Subset(65, '\uFEFF', '\uFFFF');
/**
* All Latin character blocks combined into one.
* Informative block added by Sun.
* U+0000 - U+024F
*/
public final static Subset LATIN = new Subset('\u0000', '\u024F');
/**
* All Latin digits.
* Informative block added by Sun.
* U+0030 - U+0039
*/
public final static Subset LATIN_DIGITS = new Subset('\u0030', '\u0039');
/**
* Halfwidth Katakana characters.
* Informative block added by Sun.
* U+FF60 - U+FF9F
*/
public final static Subset HALFWIDTH_KATAKANA = new Subset('\uFF60', '\uFF9F');
/**
* All Han characters used for writing traditional Chinese.
* Loosely defined as Unicode characters which
* have mappings to CNS 11643 or BigFive.
* Informative block added by Sun.
*/
public final static Subset TRADITIONAL_HANZI = new Subset();
/**
* All Han characters used for writing simplified Chinese.
* Loosely defined as Unicode characters which
* have mappings to GB 2312.
* Informative block added by Sun.
*/
public final static Subset SIMPLIFIED_HANZI = new Subset();
/**
* All Han characters used for writing Japanese.
* Loosely defined as Unicode characters which
* have mappings to JIS X 0208 or JIS X 0212.
* Informative block added by Sun.
*/
public final static Subset KANJI = new Subset();
/**
* All Han characters used for writing Korean.
* Loosely defined as Unicode characters which
* have mappings to KS C 5601.
* Informative block added by Sun.
*/
public final static Subset HANJA = new Subset();
};
/**
* The immutable value of this Character.
*/
private final char value;
static final long serialVersionUID = 3786198910865385080L;
/**
* The minimum value the char data type can hold.
* This value is U+0000.
*/
public static final char MIN_VALUE = '\u0000';
/**
* The maximum value the char data type can hold.
* This value is U+FFFF.
*/
public static final char MAX_VALUE = '\uFFFF';
/**
* Smallest value allowed for radix arguments in Java.
* This value is 2.
*/
public static final int MIN_RADIX = 2;
/**
* Largest value allowed for radix arguments in Java.
* This value is 36.
*/
public static final int MAX_RADIX = 36;
/**
* Class object representing the primitive char data type.
*/
public static final Class TYPE = VMClassLoader.getPrimitiveClass('C');
/**
* Cn = Other, Not Assigned (Normative)
*/
public static final byte UNASSIGNED = 0;
/**
* Lu = Letter, Uppercase (Informative)
*/
public static final byte UPPERCASE_LETTER = 1;
/**
* Ll = Letter, Lowercase (Informative)
*/
public static final byte LOWERCASE_LETTER = 2;
/**
* Lt = Letter, Titlecase (Informative)
*/
public static final byte TITLECASE_LETTER = 3;
/**
* Lm = Letter, Modifier (Informative)
*/
public static final byte MODIFIER_LETTER = 4;
/**
* Lo = Letter, Other (Informative)
*/
public static final byte OTHER_LETTER = 5;
/**
* Mn = Mark, Non-Spacing (Normative)
*/
public static final byte NON_SPACING_MARK = 6;
/**
* Me = Mark, Enclosing (Normative)
*/
public static final byte ENCLOSING_MARK = 7;
/**
* Mc = Mark, Spacing Combining (Normative)
*/
public static final byte COMBINING_SPACING_MARK = 8;
/**
* Nd = Number, Decimal Digit (Normative)
*/
public static final byte DECIMAL_DIGIT_NUMBER = 9;
/**
* Nl = Number, Letter (Normative)
*/
public static final byte LETTER_NUMBER = 10;
/**
* No = Number, Other (Normative)
*/
public static final byte OTHER_NUMBER = 11;
/**
* Zs = Separator, Space (Normative)
*/
public static final byte SPACE_SEPARATOR = 12;
/**
* Zl = Separator, Line (Normative)
*/
public static final byte LINE_SEPARATOR = 13;
/**
* Zp = Separator, Paragraph (Normative)
*/
public static final byte PARAGRAPH_SEPARATOR = 14;
/**
* Cc = Other, Control (Normative)
*/
public static final byte CONTROL = 15;
/**
* Cf = Other, Format (Normative)
*/
public static final byte FORMAT = 16;
// 17 is skipped (don't ask me why)
/**
* Co = Other, Private Use (Normative)
*/
public static final byte PRIVATE_USE = 18;
/**
* Cs = Other, Surrogate (Normative)
*/
public static final byte SURROGATE = 19;
/**
* Pd = Punctuation, Dash (Informative)
*/
public static final byte DASH_PUNCTUATION = 20;
/**
* Ps = Punctuation, Open (Informative)
*/
public static final byte START_PUNCTUATION = 21;
/**
* Pe = Punctuation, Close (Informative)
*/
public static final byte END_PUNCTUATION = 22;
/**
* Pc = Punctuation, Connector (Informative)
*/
public static final byte CONNECTOR_PUNCTUATION = 23;
/**
* Po = Punctuation, Other (Informative)
*/
public static final byte OTHER_PUNCTUATION = 24;
/**
* Sm = Symbol, Math (Informative)
*/
public static final byte MATH_SYMBOL = 25;
/**
* Sc = Symbol, Currency (Informative)
*/
public static final byte CURRENCY_SYMBOL = 26;
/**
* Sk = Symbol, Modifier (Informative)
*/
public static final byte MODIFIER_SYMBOL = 27;
/**
* So = Symbol, Other (Informative)
*/
public static final byte OTHER_SYMBOL = 28;
static Block blocks[]; // block.uni
static char tcs[][]; // titlecase.uni
static byte[] unicodeData; // character.uni
static CharAttr cachedCharAttr;
// open up the Unicode attribute database and read the index into memory
static {
File cFile = ClassLoaderHelper.getSystemResourceAsFile(
"/gnu/java/locale/character.uni");
File blockFile = ClassLoaderHelper.getSystemResourceAsFile(
"/gnu/java/locale/block.uni");
File tcFile = ClassLoaderHelper.getSystemResourceAsFile(
"/gnu/java/locale/titlecase.uni");
if (cFile == null || blockFile == null || tcFile == null)
throw new Error("Cannot locate Unicode attribute database.");
blocks = new Block[(int) blockFile.length() / 9];
try {
DataInputStream blockIS =
new DataInputStream(new FileInputStream(blockFile));
for (int i = 0; i < blocks.length; i++) {
char start = blockIS.readChar();
char end = blockIS.readChar();
boolean compressed = (blockIS.readUnsignedByte() != 0);
int offset = blockIS.readInt();
blocks[i] = new Block(start, end, compressed, offset);
}
} catch (IOException e) {
throw new Error("Error reading block file: " + e);
}
tcs = new char[(int) tcFile.length() / 4][2];
try {
DataInputStream tcIS = new DataInputStream(new FileInputStream(tcFile));
for (int i = 0; i < tcs.length; i++) {
tcs[i][0] = tcIS.readChar();
tcs[i][1] = tcIS.readChar();
}
} catch (IOException e) {
throw new Error("Error reading titlecase file: " + e);
}
try {
RandomAccessFile charFile = new RandomAccessFile(cFile, "r");
unicodeData = new byte[(int)charFile.length()];
charFile.readFully(unicodeData, 0, unicodeData.length);
} catch (IOException e) {
throw new Error("Unable to open Unicode character attribute file: " + e);
}
cachedCharAttr = new CharAttr((char)0, false, CONTROL, 65535,
(char)0, (char)0);
}
/**
* Grabs a character out of the Unicode attribute database.
*/
private static CharAttr readChar(char ch) {
CharAttr cached = cachedCharAttr;
if (cached.ch == ch)
return cached;
int i = getBlock(ch);
if (i == -1) return new CharAttr(ch, false, UNASSIGNED, 65535, ch, ch);
Block b = blocks[i];
int offset = (b.compressed) ? b.offset : (b.offset + (ch-b.start)*7);
int byte7 = unicodeData[offset] & 0xFF;
boolean noBreakSpace = ((byte7 >> 5 & 0x1) == 1);
int category = byte7 & 0x1F;
int numericalDecimalValue = (((unicodeData[offset+1] & 0xFF) << 8) +
(unicodeData[offset+2] & 0xFF));
char uppercase = (char)(((unicodeData[offset+3] & 0xFF) << 8) +
(unicodeData[offset+4] & 0xFF));
char lowercase = (char)(((unicodeData[offset+5] & 0xFF) << 8) +
(unicodeData[offset+6] & 0xFF));
CharAttr ca = new CharAttr(ch, noBreakSpace, category,
numericalDecimalValue, uppercase, lowercase);
cachedCharAttr = ca;
return ca;
}
/**
* Locates which block a character's information resides in
*/
private static int getBlock(char ch) {
// simple binary search
int low = 0;
int hi = blocks.length-1;
int mid = 0;
while (low <= hi) {
mid = (low + hi) >> 1;
Block b = blocks[mid];
if (ch < b.start)
hi = mid - 1;
else if (ch > b.end)
low = mid + 1;
else return mid;
}
return -1;
}
/**
* Wraps up a character.
*
* @param value the character to wrap
*/
public Character(char value) {
this.value = value;
}
/**
* Returns the character which has been wrapped by this class.
*
* @return the character wrapped
*/
public char charValue() {
return value;
}
/**
* Returns the numerical value (unsigned) of the wrapped character.
* Range of returned values: 0x0000-0xFFFF.
*
* @return an integer representing the numerical value of the
* wrapped character
*/
public int hashCode() {
return (int) value;
}
/**
* Determines if an object is equal to this object.
*
* @param o object to compare
*
* @return true if o is an instance of Character and has the
* same wrapped character, else false
*/
public boolean equals(Object o) {
return (o instanceof Character && value == ((Character)o).value);
}
/**
* Converts the wrapped character into a String.
*
* @return a String containing one character -- the wrapped character
* of this class
*/
public String toString() {
return String.valueOf(value);
}
/**
* Returns the Unicode general category property of a character.
*
* @param ch character from which the general category property will
* be retrieved
*
* @return the character category property of ch as an integer
*
* @see java.lang.Character#UNASSIGNED
* @see java.lang.Character#UPPERCASE_LETTER
* @see java.lang.Character#LOWERCASE_LETTER
* @see java.lang.Character#TITLECASE_LETTER
* @see java.lang.Character#MODIFIER_LETTER
* @see java.lang.Character#OTHER_LETTER
* @see java.lang.Character#NON_SPACING_MARK
* @see java.lang.Character#ENCLOSING_MARK
* @see java.lang.Character#COMBINING_SPACING_MARK
* @see java.lang.Character#DECIMAL_DIGIT_NUMBER
* @see java.lang.Character#LETTER_NUMBER
* @see java.lang.Character#OTHER_NUMBER
* @see java.lang.Character#SPACE_SEPARATOR
* @see java.lang.Character#LINE_SEPARATOR
* @see java.lang.Character#PARAGRAPH_SEPARATOR
* @see java.lang.Character#CONTROL
* @see java.lang.Character#FORMAT
* @see java.lang.Character#PRIVATE_USE
* @see java.lang.Character#SURROGATE
* @see java.lang.Character#DASH_PUNCTUATION
* @see java.lang.Character#START_PUNCTUATION
* @see java.lang.Character#END_PUNCTUATION
* @see java.lang.Character#CONNECTOR_PUNCTUATION
* @see java.lang.Character#OTHER_PUNCTUATION
* @see java.lang.Character#MATH_SYMBOL
* @see java.lang.Character#CURRENCY_SYMBOL
* @see java.lang.Character#MODIFIER_SYMBOL
*/
public static int getType(char ch) {
return readChar(ch).getType();
}
/**
* Returns the Unicode numeric value property of a character.
* If the character lacks a numeric value property, -1 is returned.
* If the character has a numeric value property which is not
* representable as a nonnegative integer, -2 is returned.
*
* @param ch character from which the numeric value property will
* be retrieved
*
* @return the numeric value property of ch, or -1 if it does not exist, or
* -2 if it is not representable as a nonnegative integer
*/
public static int getNumericValue(char ch) {
return readChar(ch).getNumericValue();
}
/**
* Determines if a character is a Unicode decimal digit.
* <br>
* Unicode decimal digit = [Nd]
*
* @param ch character to test
*
* @return true if ch is a Unicode decimal digit, else false
*/
public static boolean isDigit(char ch) {
return (getType(ch) == DECIMAL_DIGIT_NUMBER);
}
/**
* Converts a character into a digit of the specified radix.
* <br>
* character argument boundary = [Nd]|U+0041-U+005A|U+0061-007A
*
* @param ch character to convert into a digit
* @param radix radix in which ch is a digit
*
* @return digit which ch represents in radix, or -1
* if radix < MIN_RADIX or radix > MAX_RADIX or ch is not
* a valid digit in radix
*
* @see java.lang.Character#MIN_RADIX
* @see java.lang.Character#MAX_RADIX
*/
public static int digit(char ch, int radix) {
if (radix < MIN_RADIX || radix > MAX_RADIX)
return -1;
CharAttr attr = readChar(ch);
if (attr.getType() == DECIMAL_DIGIT_NUMBER &&
attr.getNumericValue() < radix)
return attr.getNumericValue();
if (ch >= 'A' && ch <= 'Z' && ch < radix+'A'-10)
return ch-'A'+10;
if (ch >= 'a' && ch <= 'z' && ch < radix+'a'-10)
return ch-'a'+10;
return -1;
}
/**
* Converts a digit into a character which represents that digit
* in a specified radix.
* <br>
* return value boundary = U+0030-U+0039|U+0061-U+007A
*
* @param digit digit to be converted into a character
* @param radix radix of digit
*
* @return character representing digit in radix, or U+0000 if
* radix < MIN_RADIX or radix > MAX_RADIX or digit < 0 or
* digit >= radix
*
* @see java.lang.Character#MIN_RADIX
* @see java.lang.Character#MAX_RADIX
*/
public static char forDigit(int digit, int radix) {
if (radix < MIN_RADIX || radix > MAX_RADIX ||
digit < 0 || digit >= radix)
return '\u0000';
return (char) ((digit < 10) ? ('0' + digit) : ('a'+digit-10));
}
/**
* Determines if a character is a Unicode space character.
* <br>
* Unicode space = [Zs]
*
* @param ch character to test
*
* @return true if ch is a Unicode space, else false
*/
public static boolean isSpaceChar(char ch) {
return (getType(ch) == SPACE_SEPARATOR);
}
/**
* Determines if a character is a Java space, per JLS 20.5.19.
* <br>
* Java space = U+0020|U+0009|U+000A|U+000C|U+000D
*
* @param ch character to test
*
* @return true if ch is a Java space, else false
*
* @deprecated Replaced by isWhitespace()
*/
public static boolean isSpace(char ch) {
return ((ch == ' ') || (ch == '\t') || (ch == '\n') || (ch == '\f') ||
(ch == '\r'));
}
/**
* Determines if a character is Java whitespace.
* <br>
* Java whitespace = ([Zs] not Nb)|[Zl]|[Zp]|U+0009-U+000D|U+001C-U+001F
*
* @param ch character to test
*
* @return true if ch is Java whitespace, else false
*/
public static boolean isWhitespace(char ch) {
CharAttr attr = readChar(ch);
int category = attr.getType();
return ((category == SPACE_SEPARATOR && !attr.isNoBreakSpace()) ||
category == LINE_SEPARATOR ||
category == PARAGRAPH_SEPARATOR ||
//(ch >= '\u0009' && ch <= '\ u000D') ||
(ch >= '\u0009' && ch <= '\r') || // Change to make javadep work
(ch >= '\u001C' && ch <= '\u001F'));
}
/**
* Determines if a character has the ISO Control property.
* <br>
* ISO Control = U+0000-U+001F|U+0074-U+0094
*
* @param ch character to test
*
* @return true if ch is an ISO Control character, else false
*/
public static boolean isISOControl(char ch) {
return ((ch >= '\u0000' && ch <= '\u001F') ||
(ch >= '\u007F' && ch <= '\u009F'));
}
/**
* Determines if a character is part of the Unicode Standard.
* <br>
* defined = not [Cn]
*
* @param ch character to test
*
* @return true if ch is a Unicode character, else false
*/
public static boolean isDefined(char ch) {
return (getBlock(ch) != -1);
}
/**
* Determines if a character is a Unicode letter.
* <br>
* letter = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]
*
* @param ch character to test
*
* @return true if ch is a Unicode letter, else false
*/
public static boolean isLetter(char ch) {
int category = getType(ch);
return ((category >= UPPERCASE_LETTER && category <= OTHER_LETTER) ||
(category == LETTER_NUMBER));
}
/**
* Determines if a character is a Unicode letter or a Unicode digit.
* <br>
* letter or digit = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Nd]
*
* @param ch character to test
*
* @return true if ch is a Unicode letter or a Unicode digit, else false
*/
public static boolean isLetterOrDigit(char ch) {
int category = getType(ch);
return ((category >= UPPERCASE_LETTER && category <= OTHER_LETTER) ||
(category == LETTER_NUMBER) ||
(category == DECIMAL_DIGIT_NUMBER));
}
/**
* Determines if a character is a Unicode lowercase letter.
* <br>
* lowercase = [Ll]
*
* @param ch character to test
*
* @return true if ch is a Unicode lowercase letter, else false
*/
public static boolean isLowerCase(char ch) {
return (getType(ch) == LOWERCASE_LETTER);
}
/**
* Converts a Unicode character into its lowercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
*
* @param ch character to convert to lowercase
*
* @return lowercase mapping of ch, or ch if lowercase mapping does
* not exist.
*/
public static char toLowerCase(char ch) {
return readChar(ch).toLowerCase();
}
/**
* Determines if a character is a Unicode uppercase letter.
* <br>
* uppercase = [Lu]
*
* @param ch character to test
*
* @return true if ch is a Unicode uppercase letter, else false
*/
public static boolean isUpperCase(char ch) {
return (getType(ch) == UPPERCASE_LETTER);
}
/**
* Converts a Unicode character into its uppercase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
*
* @param ch character to convert to uppercase
*
* @return uppercase mapping of ch, or ch if uppercase mapping does
* not exist.
*/
public static char toUpperCase(char ch) {
return readChar(ch).toUpperCase();
}
/**
* Determines if a character is a Unicode titlecase letter.
* <br>
* titlecase = [Lt]
*
* @param ch character to test
*
* @return true if ch is a Unicode titlecase letter, else false
*/
public static boolean isTitleCase(char ch) {
return (getType(ch) == TITLECASE_LETTER);
}
/**
* Converts a Unicode character into its titlecase equivalent mapping.
* If a mapping does not exist, then the character passed is returned.
*
* @param ch character to convert to titlecase
*
* @return titlecase mapping of ch, or ch if titlecase mapping does
* not exist.
*/
public static char toTitleCase(char ch) {
for (int i = 0; i < tcs.length; i++)
if (tcs[i][0] == ch)
return tcs[i][1];
return toUpperCase(ch);
}
/**
* Determines if a character can start a Java identifier.
* This method does not implement JLS 20.5.17, but instead
* implements the algorithm used by isJavaIdentifierStart().
*
* @param ch character to test
*
* @return true if ch can start a Java identifier, else false
*
* @deprecated Replaced by isJavaIdentifierStart()
*
* @see java.lang.Character#isJavaIdentifierStart
*/
public static boolean isJavaLetter(char ch) {
return isJavaIdentifierStart(ch);
}
/**
* Determines if a character can follow the first letter in
* a Java identifier. This method does not implement JLS 20.5.18,
* but instead implements the algorithm used by isJavaIdentifierPart().
*
* @param ch character to test
*
* @return true if ch can follow the first letter in a Java identifier,
* else false
*
* @deprecated Replaced by isJavaIdentifierPart()
*
* @see java.lang.Character#isJavaIdentifierPart
*/
public static boolean isJavaLetterOrDigit(char ch) {
return isJavaIdentifierPart(ch);
}
/**
* Determines if a character can start a Java identifier.
* <br>
* Java identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc]
*
* @param ch character to test
*
* @return true if ch can start a Java identifier, else false
*/
public static boolean isJavaIdentifierStart(char ch) {
int category = getType(ch);
return ((category >= UPPERCASE_LETTER && category <= OTHER_LETTER) ||
(category == CURRENCY_SYMBOL) ||
(category == CONNECTOR_PUNCTUATION));
}
/**
* Determines if a character can follow the first letter in
* a Java identifier.
* <br>
* Java identifier extender =
* [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Sc]|[Pc][Mn]|[Mc]|[Nd]|[Cf]
*
* @param ch character to test
*
* @return true if ch can follow the first letter in a Java identifier,
* else false
*/
public static boolean isJavaIdentifierPart(char ch) {
int category = getType(ch);
return ((category >= UPPERCASE_LETTER && category <= OTHER_LETTER) ||
(category == LETTER_NUMBER) ||
(category == CURRENCY_SYMBOL) ||
(category == NON_SPACING_MARK) ||
(category == COMBINING_SPACING_MARK) ||
(category == DECIMAL_DIGIT_NUMBER) ||
(category == CONNECTOR_PUNCTUATION) ||
(category == FORMAT));
}
/**
* Determines if a character can start a Unicode identifier. Only
* letters can start a Unicode identifier.
* <br>
* Unicode identifier start = [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]
*
* @param ch character to test
*
* @return true if ch can start a Unicode identifier, else false
*/
public static boolean isUnicodeIdentifierStart(char ch) {
return isLetter(ch);
}
/**
* Determines if a character can follow the first letter in
* a Unicode identifier.
* <br>
* Unicode identifier extender =
* [Lu]|[Ll]|[Lt]|[Lm]|[Lo]|[Nl]|[Mn]|[Mc]|[Nd]|[Pc]|[Cf]
*
* @param ch character to test
*
* @return true if ch can follow the first letter in a Unicode identifier,
* else false
*/
public static boolean isUnicodeIdentifierPart(char ch) {
int category = getType(ch);
return ((category >= UPPERCASE_LETTER && category <= OTHER_LETTER) ||
(category == LETTER_NUMBER) ||
(category == NON_SPACING_MARK) ||
(category == COMBINING_SPACING_MARK) ||
(category == DECIMAL_DIGIT_NUMBER) ||
(category == CONNECTOR_PUNCTUATION) ||
(category == FORMAT));
}
/**
* Determines if a character is ignorable in a Unicode identifier.
* <br>
* Unicode identifier ignorable = [Cf]
*
* @param ch character to test
*
* @return true if ch is ignorable in a Unicode identifier,
* else false
*/
public static boolean isIdentifierIgnorable(char ch) {
return (getType(ch) == FORMAT);
}
/**
* Determines the Unicode character block that a character belongs to.
*
* @param ch character for which the Unicode character block will
* be retrieved
*
* @return the Unicode character block which ch belongs to, or null
* if ch does not belong to any Unicode character block
*
* @see java.lang.Character.Subset
*/
public static Character.Subset getUnicodeBlock(char ch) {
return Character.Subset.getBlock(ch);
}
/**
* Compares another Character to this Character, numerically.
*
* @param anotherCharacter Character to compare with this Character
*
* @return a negative integer if this Character is less than
* anotherCharacter, zero if this Character is equal to anotherCharacter, or
* a positive integer if this Character is greater than anotherCharacter
*
* @exception NullPointerException if anotherCharacter is null
*/
public int compareTo(Character anotherCharacter)
throws NullPointerException {
return value - anotherCharacter.value;
}
/**
* Compares an object to this Character. Assuming the object is a
* Character object, this method performs the same comparison as
* compareTo(Character).
*
* @param o object to compare
*
* @return a negative integer if this Character is less than o,
* zero if this Character is equal to o, or a positive integer if this
* Character is greater than o
*
* @exception ClassCastException if o is not a Character object
* @exception NullPointerException if o is null
*
* @see java.lang.Character#compareTo(Character)
*/
public int compareTo(Object o)
throws ClassCastException, NullPointerException {
return compareTo((Character)o);
}
}
/**
* Represents an entry in block.uni
*/
final class Block {
char start;
char end;
boolean compressed;
int offset;
Block(char start, char end, boolean compressed, int offset) {
this.start = start;
this.end = end;
this.compressed = compressed;
this.offset = offset;
}
}
/**
* Represents all the attributes stored for a character.
*/
final class CharAttr {
boolean noBreakSpace;
int category;
int numericalDecimalValue;
char uppercase;
char lowercase;
char ch;
CharAttr(char ch, boolean noBreakSpace, int category,
int numericalDecimalValue,
char uppercase, char lowercase) {
this.noBreakSpace = noBreakSpace;
this.category = category;
this.numericalDecimalValue = numericalDecimalValue;
this.uppercase = uppercase;
this.lowercase = lowercase;
this.ch = ch;
}
boolean isNoBreakSpace() {
return noBreakSpace;
}
int getNumericValue() {
if (numericalDecimalValue == 65535) return -1;
if (numericalDecimalValue == 65534) return -2;
return numericalDecimalValue;
}
int getType() {
return category;
}
char toUpperCase() {
return (uppercase != 0) ? uppercase : ch;
}
char toLowerCase() {
return (lowercase != 0) ? lowercase : ch;
}
}
|