1. // This file was generated AUTOMATICALLY from a template file Wed Sep 15 03:12:53 PDT 2004
  2. /* @(#)CharacterData02.java.template 1.3 03/07/26
  3. *
  4. * Copyright 1994-2002 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.lang;
  11. /** The CharacterData class encapsulates the large tables found in
  12. Java.lang.Character. */
  13. class CharacterData02 {
  14. /* The character properties are currently encoded into 32 bits in the following manner:
  15. 1 bit mirrored property
  16. 4 bits directionality property
  17. 9 bits signed offset used for converting case
  18. 1 bit if 1, adding the signed offset converts the character to lowercase
  19. 1 bit if 1, subtracting the signed offset converts the character to uppercase
  20. 1 bit if 1, this character has a titlecase equivalent (possibly itself)
  21. 3 bits 0 may not be part of an identifier
  22. 1 ignorable control; may continue a Unicode identifier or Java identifier
  23. 2 may continue a Java identifier but not a Unicode identifier (unused)
  24. 3 may continue a Unicode identifier or Java identifier
  25. 4 is a Java whitespace character
  26. 5 may start or continue a Java identifier;
  27. may continue but not start a Unicode identifier (underscores)
  28. 6 may start or continue a Java identifier but not a Unicode identifier ($)
  29. 7 may start or continue a Unicode identifier or Java identifier
  30. Thus:
  31. 5, 6, 7 may start a Java identifier
  32. 1, 2, 3, 5, 6, 7 may continue a Java identifier
  33. 7 may start a Unicode identifier
  34. 1, 3, 5, 7 may continue a Unicode identifier
  35. 1 is ignorable within an identifier
  36. 4 is Java whitespace
  37. 2 bits 0 this character has no numeric property
  38. 1 adding the digit offset to the character code and then
  39. masking with 0x1F will produce the desired numeric value
  40. 2 this character has a "strange" numeric value
  41. 3 a Java supradecimal digit: adding the digit offset to the
  42. character code, then masking with 0x1F, then adding 10
  43. will produce the desired numeric value
  44. 5 bits digit offset
  45. 5 bits character type
  46. The encoding of character properties is subject to change at any time.
  47. */
  48. static int getProperties(int ch) {
  49. char offset = (char)ch;
  50. int props = A[Y[X[offset>>5]|((offset>>1)&0xF)]|(offset&0x1)];
  51. return props;
  52. }
  53. static int getType(int ch) {
  54. int props = getProperties(ch);
  55. return (props & 0x1F);
  56. }
  57. static boolean isLowerCase(int ch) {
  58. int type = getType(ch);
  59. return (type == Character.LOWERCASE_LETTER);
  60. }
  61. static boolean isUpperCase(int ch) {
  62. int type = getType(ch);
  63. return (type == Character.UPPERCASE_LETTER);
  64. }
  65. static boolean isTitleCase(int ch) {
  66. int type = getType(ch);
  67. return (type == Character.TITLECASE_LETTER);
  68. }
  69. static boolean isDigit(int ch) {
  70. int type = getType(ch);
  71. return (type == Character.DECIMAL_DIGIT_NUMBER);
  72. }
  73. static boolean isDefined(int ch) {
  74. int type = getType(ch);
  75. return (type != Character.UNASSIGNED);
  76. }
  77. static boolean isLetter(int ch) {
  78. int type = getType(ch);
  79. return (((((1 << Character.UPPERCASE_LETTER) |
  80. (1 << Character.LOWERCASE_LETTER) |
  81. (1 << Character.TITLECASE_LETTER) |
  82. (1 << Character.MODIFIER_LETTER) |
  83. (1 << Character.OTHER_LETTER)) >> type) & 1) != 0);
  84. }
  85. static boolean isLetterOrDigit(int ch) {
  86. int type = getType(ch);
  87. return (((((1 << Character.UPPERCASE_LETTER) |
  88. (1 << Character.LOWERCASE_LETTER) |
  89. (1 << Character.TITLECASE_LETTER) |
  90. (1 << Character.MODIFIER_LETTER) |
  91. (1 << Character.OTHER_LETTER) |
  92. (1 << Character.DECIMAL_DIGIT_NUMBER)) >> type) & 1) != 0);
  93. }
  94. static boolean isSpaceChar(int ch) {
  95. int type = getType(ch);
  96. return (((((1 << Character.SPACE_SEPARATOR) |
  97. (1 << Character.LINE_SEPARATOR) |
  98. (1 << Character.PARAGRAPH_SEPARATOR)) >> type) & 1) != 0);
  99. }
  100. static boolean isJavaIdentifierStart(int ch) {
  101. int props = getProperties(ch);
  102. return ((props & 0x00007000) >= 0x00005000);
  103. }
  104. static boolean isJavaIdentifierPart(int ch) {
  105. int props = getProperties(ch);
  106. return ((props & 0x00003000) != 0);
  107. }
  108. static boolean isUnicodeIdentifierStart(int ch) {
  109. int props = getProperties(ch);
  110. return ((props & 0x00007000) == 0x00007000);
  111. }
  112. static boolean isUnicodeIdentifierPart(int ch) {
  113. int props = getProperties(ch);
  114. return ((props & 0x00001000) != 0);
  115. }
  116. static boolean isIdentifierIgnorable(int ch) {
  117. int props = getProperties(ch);
  118. return ((props & 0x00007000) == 0x00001000);
  119. }
  120. static int toLowerCase(int ch) {
  121. int mapChar = ch;
  122. int val = getProperties(ch);
  123. if ((val & 0x00020000) != 0) {
  124. int offset = val << 5 >> (5+18);
  125. mapChar = ch + offset;
  126. }
  127. return mapChar;
  128. }
  129. static int toUpperCase(int ch) {
  130. int mapChar = ch;
  131. int val = getProperties(ch);
  132. if ((val & 0x00010000) != 0) {
  133. int offset = val << 5 >> (5+18);
  134. mapChar = ch - offset;
  135. }
  136. return mapChar;
  137. }
  138. static int toTitleCase(int ch) {
  139. int mapChar = ch;
  140. int val = getProperties(ch);
  141. if ((val & 0x00008000) != 0) {
  142. // There is a titlecase equivalent. Perform further checks:
  143. if ((val & 0x00010000) == 0) {
  144. // The character does not have an uppercase equivalent, so it must
  145. // already be uppercase; so add 1 to get the titlecase form.
  146. mapChar = ch + 1;
  147. }
  148. else if ((val & 0x00020000) == 0) {
  149. // The character does not have a lowercase equivalent, so it must
  150. // already be lowercase; so subtract 1 to get the titlecase form.
  151. mapChar = ch - 1;
  152. }
  153. // else {
  154. // The character has both an uppercase equivalent and a lowercase
  155. // equivalent, so it must itself be a titlecase form; return it.
  156. // return ch;
  157. //}
  158. }
  159. else if ((val & 0x00010000) != 0) {
  160. // This character has no titlecase equivalent but it does have an
  161. // uppercase equivalent, so use that (subtract the signed case offset).
  162. mapChar = toUpperCase(ch);
  163. }
  164. return mapChar;
  165. }
  166. static int digit(int ch, int radix) {
  167. int value = -1;
  168. if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
  169. int val = getProperties(ch);
  170. int kind = val & 0x1F;
  171. if (kind == Character.DECIMAL_DIGIT_NUMBER) {
  172. value = ch + ((val & 0x3E0) >> 5) & 0x1F;
  173. }
  174. else if ((val & 0xC00) == 0x00000C00) {
  175. // Java supradecimal digit
  176. value = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  177. }
  178. }
  179. return (value < radix) ? value : -1;
  180. }
  181. static int getNumericValue(int ch) {
  182. int val = getProperties(ch);
  183. int retval = -1;
  184. switch (val & 0xC00) {
  185. default: // cannot occur
  186. case (0x00000000): // not numeric
  187. retval = -1;
  188. break;
  189. case (0x00000400): // simple numeric
  190. retval = ch + ((val & 0x3E0) >> 5) & 0x1F;
  191. break;
  192. case (0x00000800) : // "strange" numeric
  193. retval = -2;
  194. break;
  195. case (0x00000C00): // Java supradecimal
  196. retval = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  197. break;
  198. }
  199. return retval;
  200. }
  201. static boolean isWhitespace(int ch) {
  202. return (getProperties(ch) & 0x00007000) == 0x00004000;
  203. }
  204. static byte getDirectionality(int ch) {
  205. int val = getProperties(ch);
  206. byte directionality = (byte)((val & 0x78000000) >> 27);
  207. if (directionality == 0xF ) {
  208. directionality = Character.DIRECTIONALITY_UNDEFINED;
  209. }
  210. return directionality;
  211. }
  212. static boolean isMirrored(int ch) {
  213. return (getProperties(ch) & 0x80000000) != 0;
  214. }
  215. // may need to implement for JSR 204
  216. // static int toUpperCaseEx(int ch);
  217. // static char[] toUpperCaseCharArray(int ch);
  218. // The following tables and code generated using:
  219. // java GenerateCharacter -plane 2 -template ../../tools/GenerateCharacter/CharacterData02.java.template -spec ../../tools/GenerateCharacter/UnicodeData.txt -specialcasing ../../tools/GenerateCharacter/SpecialCasing.txt -o C:/BUILD_AREA/jdk1.5.0/control/build/windows-i586/gensrc/java/lang/CharacterData02.java -string -usecharforbyte 11 4 1
  220. // The X table has 2048 entries for a total of 4096 bytes.
  221. static final char X[] = (
  222. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  223. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  224. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  225. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  226. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  227. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  228. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  229. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  230. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  231. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  232. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  233. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  234. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  235. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  236. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  237. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  238. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  239. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  240. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  241. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  242. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  243. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  244. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  245. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  246. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  247. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  248. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  249. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  250. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  251. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  252. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  253. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  254. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  255. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  256. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  257. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  258. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  259. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  260. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  261. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  262. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  263. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  264. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  265. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  266. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  267. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  268. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  269. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  270. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  271. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  272. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  273. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  274. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  275. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  276. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  277. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  278. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  279. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  280. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  281. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  282. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  283. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  284. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  285. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  286. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  287. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  288. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  289. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  290. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  291. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  292. "\000\000\000\000\020\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  293. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  294. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  295. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  296. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  297. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  298. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  299. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  300. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  301. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  302. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  303. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  304. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  305. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  306. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  307. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  308. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  309. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  310. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  311. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  312. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  313. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  314. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  315. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  316. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  317. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  318. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  319. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  320. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  321. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  322. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  323. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  324. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  325. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  326. "\040\040\040\040\040\040\040\040\000\000\000\000\000\000\000\000\000\000\000"+
  327. "\000\000\000\000\000\060\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  328. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  329. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040").toCharArray();
  330. // The Y table has 64 entries for a total of 128 bytes.
  331. static final char Y[] = (
  332. "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"+
  333. "\000\000\000\000\000\000\000\000\002\004\004\004\004\004\004\004\004\004\004"+
  334. "\004\004\004\004\004\004\004\004\004\004\000\000\000\000\000\000\000\000\000"+
  335. "\000\000\000\000\000\000\004").toCharArray();
  336. // The A table has 6 entries for a total of 24 bytes.
  337. static final int A[] = new int[6];
  338. static final String A_DATA =
  339. "\000\u7005\000\u7005\000\u7005\u7800\000\u7800\000\u7800\000";
  340. // In all, the character property tables require 4248 bytes.
  341. static {
  342. { // THIS CODE WAS AUTOMATICALLY CREATED BY GenerateCharacter:
  343. char[] data = A_DATA.toCharArray();
  344. assert (data.length == (6 * 2));
  345. int i = 0, j = 0;
  346. while (i < (6 * 2)) {
  347. int entry = data[i++] << 16;
  348. A[j++] = entry | data[i++];
  349. }
  350. }
  351. }
  352. }