1. // This file was generated AUTOMATICALLY from a template file Wed Sep 15 03:12:54 PDT 2004
  2. /* @(#)CharacterData0E.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 CharacterData0E {
  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))
  99. >> type) & 1) != 0);
  100. }
  101. static boolean isJavaIdentifierStart(int ch) {
  102. int props = getProperties(ch);
  103. return ((props & 0x00007000) >= 0x00005000);
  104. }
  105. static boolean isJavaIdentifierPart(int ch) {
  106. int props = getProperties(ch);
  107. return ((props & 0x00003000) != 0);
  108. }
  109. static boolean isUnicodeIdentifierStart(int ch) {
  110. int props = getProperties(ch);
  111. return ((props & 0x00007000) == 0x00007000);
  112. }
  113. static boolean isUnicodeIdentifierPart(int ch) {
  114. int props = getProperties(ch);
  115. return ((props & 0x00001000) != 0);
  116. }
  117. static boolean isIdentifierIgnorable(int ch) {
  118. int props = getProperties(ch);
  119. return ((props & 0x00007000) == 0x00001000);
  120. }
  121. static int toLowerCase(int ch) {
  122. int mapChar = ch;
  123. int val = getProperties(ch);
  124. if ((val & 0x00020000) != 0) {
  125. int offset = val << 5 >> (5+18);
  126. mapChar = ch + offset;
  127. }
  128. return mapChar;
  129. }
  130. static int toUpperCase(int ch) {
  131. int mapChar = ch;
  132. int val = getProperties(ch);
  133. if ((val & 0x00010000) != 0) {
  134. int offset = val << 5 >> (5+18);
  135. mapChar = ch - offset;
  136. }
  137. return mapChar;
  138. }
  139. static int toTitleCase(int ch) {
  140. int mapChar = ch;
  141. int val = getProperties(ch);
  142. if ((val & 0x00008000) != 0) {
  143. // There is a titlecase equivalent. Perform further checks:
  144. if ((val & 0x00010000) == 0) {
  145. // The character does not have an uppercase equivalent, so it must
  146. // already be uppercase; so add 1 to get the titlecase form.
  147. mapChar = ch + 1;
  148. }
  149. else if ((val & 0x00020000) == 0) {
  150. // The character does not have a lowercase equivalent, so it must
  151. // already be lowercase; so subtract 1 to get the titlecase form.
  152. mapChar = ch - 1;
  153. }
  154. // else {
  155. // The character has both an uppercase equivalent and a lowercase
  156. // equivalent, so it must itself be a titlecase form; return it.
  157. // return ch;
  158. //}
  159. }
  160. else if ((val & 0x00010000) != 0) {
  161. // This character has no titlecase equivalent but it does have an
  162. // uppercase equivalent, so use that (subtract the signed case offset).
  163. mapChar = toUpperCase(ch);
  164. }
  165. return mapChar;
  166. }
  167. static int digit(int ch, int radix) {
  168. int value = -1;
  169. if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
  170. int val = getProperties(ch);
  171. int kind = val & 0x1F;
  172. if (kind == Character.DECIMAL_DIGIT_NUMBER) {
  173. value = ch + ((val & 0x3E0) >> 5) & 0x1F;
  174. }
  175. else if ((val & 0xC00) == 0x00000C00) {
  176. // Java supradecimal digit
  177. value = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  178. }
  179. }
  180. return (value < radix) ? value : -1;
  181. }
  182. static int getNumericValue(int ch) {
  183. int val = getProperties(ch);
  184. int retval = -1;
  185. switch (val & 0xC00) {
  186. default: // cannot occur
  187. case (0x00000000): // not numeric
  188. retval = -1;
  189. break;
  190. case (0x00000400): // simple numeric
  191. retval = ch + ((val & 0x3E0) >> 5) & 0x1F;
  192. break;
  193. case (0x00000800) : // "strange" numeric
  194. retval = -2;
  195. break;
  196. case (0x00000C00): // Java supradecimal
  197. retval = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  198. break;
  199. }
  200. return retval;
  201. }
  202. static boolean isWhitespace(int ch) {
  203. int props = getProperties(ch);
  204. return ((props & 0x00007000) == 0x00004000);
  205. }
  206. static byte getDirectionality(int ch) {
  207. int val = getProperties(ch);
  208. byte directionality = (byte)((val & 0x78000000) >> 27);
  209. if (directionality == 0xF ) {
  210. directionality = Character.DIRECTIONALITY_UNDEFINED;
  211. }
  212. return directionality;
  213. }
  214. static boolean isMirrored(int ch) {
  215. int props = getProperties(ch);
  216. return ((props & 0x80000000) != 0);
  217. }
  218. // may need to implement for JSR 204
  219. // static int toUpperCaseEx(int ch);
  220. // static char[] toUpperCaseCharArray(int ch);
  221. // The following tables and code generated using:
  222. // java GenerateCharacter -plane 14 -template ../../tools/GenerateCharacter/CharacterData0E.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/CharacterData0E.java -string -usecharforbyte 11 4 1
  223. // The X table has 2048 entries for a total of 4096 bytes.
  224. static final char X[] = (
  225. "\000\020\020\020\040\040\040\040\060\060\060\060\060\060\060\100\040\040\040"+
  226. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  227. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  228. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  229. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  230. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  231. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  232. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  233. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  234. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  235. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  236. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  237. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  238. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  239. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  240. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  241. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  242. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  243. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  244. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  245. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  246. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  247. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  248. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  249. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  250. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  251. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  252. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  253. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  254. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  255. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  256. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  257. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  258. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  259. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  260. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  261. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  262. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  263. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  264. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  265. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  266. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  267. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  268. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  269. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  270. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  271. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  272. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  273. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  274. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  275. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  276. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  277. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  278. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  279. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  280. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  281. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  282. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  283. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  284. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  285. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  286. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  287. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  288. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  289. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  290. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  291. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  292. "\040\040\040\040\040\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\040\040\040\040\040\040\040\040\040\040\040"+
  327. "\040\040\040\040\040\040\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\040\040\040\040"+
  330. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  331. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040"+
  332. "\040\040\040\040\040\040\040\040\040\040\040\040\040\040\040").toCharArray();
  333. // The Y table has 80 entries for a total of 160 bytes.
  334. static final char Y[] = (
  335. "\000\002\002\002\002\002\002\002\002\002\002\002\002\002\002\002\004\004\004"+
  336. "\004\004\004\004\004\004\004\004\004\004\004\004\004\002\002\002\002\002\002"+
  337. "\002\002\002\002\002\002\002\002\002\002\006\006\006\006\006\006\006\006\006"+
  338. "\006\006\006\006\006\006\006\006\006\006\006\006\006\006\006\002\002\002\002"+
  339. "\002\002\002\002").toCharArray();
  340. // The A table has 8 entries for a total of 32 bytes.
  341. static final int A[] = new int[8];
  342. static final String A_DATA =
  343. "\u7800\000\u4800\u1010\u7800\000\u7800\000\u4800\u1010\u4800\u1010\u4000\u3006"+
  344. "\u4000\u3006";
  345. // In all, the character property tables require 4288 bytes.
  346. static {
  347. { // THIS CODE WAS AUTOMATICALLY CREATED BY GenerateCharacter:
  348. char[] data = A_DATA.toCharArray();
  349. assert (data.length == (8 * 2));
  350. int i = 0, j = 0;
  351. while (i < (8 * 2)) {
  352. int entry = data[i++] << 16;
  353. A[j++] = entry | data[i++];
  354. }
  355. }
  356. }
  357. }