1. // This file was generated AUTOMATICALLY from a template file Wed Sep 15 03:12:50 PDT 2004
  2. /* @(#)CharacterDataLatin1.java.template 1.5 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 CharacterDataLatin1 {
  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[offset];
  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. return false;
  67. }
  68. static boolean isDigit(int ch) {
  69. int type = getType(ch);
  70. return (type == Character.DECIMAL_DIGIT_NUMBER);
  71. }
  72. static boolean isDefined(int ch) {
  73. int type = getType(ch);
  74. return (type != Character.UNASSIGNED);
  75. }
  76. static boolean isLetter(int ch) {
  77. int type = getType(ch);
  78. return (((((1 << Character.UPPERCASE_LETTER) |
  79. (1 << Character.LOWERCASE_LETTER) |
  80. (1 << Character.TITLECASE_LETTER) |
  81. (1 << Character.MODIFIER_LETTER) |
  82. (1 << Character.OTHER_LETTER)) >> type) & 1) != 0);
  83. }
  84. static boolean isLetterOrDigit(int ch) {
  85. int type = getType(ch);
  86. return (((((1 << Character.UPPERCASE_LETTER) |
  87. (1 << Character.LOWERCASE_LETTER) |
  88. (1 << Character.TITLECASE_LETTER) |
  89. (1 << Character.MODIFIER_LETTER) |
  90. (1 << Character.OTHER_LETTER) |
  91. (1 << Character.DECIMAL_DIGIT_NUMBER)) >> type) & 1) != 0);
  92. }
  93. static boolean isSpaceChar(int ch) {
  94. int type = getType(ch);
  95. return (((((1 << Character.SPACE_SEPARATOR) |
  96. (1 << Character.LINE_SEPARATOR) |
  97. (1 << Character.PARAGRAPH_SEPARATOR)) >> type) & 1) != 0);
  98. }
  99. static boolean isJavaIdentifierStart(int ch) {
  100. int props = getProperties(ch);
  101. return ((props & 0x00007000) >= 0x00005000);
  102. }
  103. static boolean isJavaIdentifierPart(int ch) {
  104. int props = getProperties(ch);
  105. return ((props & 0x00003000) != 0);
  106. }
  107. static boolean isUnicodeIdentifierStart(int ch) {
  108. int props = getProperties(ch);
  109. return ((props & 0x00007000) == 0x00007000);
  110. }
  111. static boolean isUnicodeIdentifierPart(int ch) {
  112. int props = getProperties(ch);
  113. return ((props & 0x00001000) != 0);
  114. }
  115. static boolean isIdentifierIgnorable(int ch) {
  116. int props = getProperties(ch);
  117. return ((props & 0x00007000) == 0x00001000);
  118. }
  119. static int toLowerCase(int ch) {
  120. int mapChar = ch;
  121. int val = getProperties(ch);
  122. if (((val & 0x00020000) != 0) &&
  123. ((val & 0x07FC0000) != 0x07FC0000)) {
  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. if ((val & 0x07FC0000) != 0x07FC0000) {
  134. int offset = val << 5 >> (5+18);
  135. mapChar = ch - offset;
  136. } else if (ch == 0x00B5) {
  137. mapChar = 0x039C;
  138. }
  139. }
  140. return mapChar;
  141. }
  142. static int toTitleCase(int ch) {
  143. return toUpperCase(ch);
  144. }
  145. static int digit(int ch, int radix) {
  146. int value = -1;
  147. if (radix >= Character.MIN_RADIX && radix <= Character.MAX_RADIX) {
  148. int val = getProperties(ch);
  149. int kind = val & 0x1F;
  150. if (kind == Character.DECIMAL_DIGIT_NUMBER) {
  151. value = ch + ((val & 0x3E0) >> 5) & 0x1F;
  152. }
  153. else if ((val & 0xC00) == 0x00000C00) {
  154. // Java supradecimal digit
  155. value = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  156. }
  157. }
  158. return (value < radix) ? value : -1;
  159. }
  160. static int getNumericValue(int ch) {
  161. int val = getProperties(ch);
  162. int retval = -1;
  163. switch (val & 0xC00) {
  164. default: // cannot occur
  165. case (0x00000000): // not numeric
  166. retval = -1;
  167. break;
  168. case (0x00000400): // simple numeric
  169. retval = ch + ((val & 0x3E0) >> 5) & 0x1F;
  170. break;
  171. case (0x00000800) : // "strange" numeric
  172. retval = -2;
  173. break;
  174. case (0x00000C00): // Java supradecimal
  175. retval = (ch + ((val & 0x3E0) >> 5) & 0x1F) + 10;
  176. break;
  177. }
  178. return retval;
  179. }
  180. static boolean isWhitespace(int ch) {
  181. int props = getProperties(ch);
  182. return ((props & 0x00007000) == 0x00004000);
  183. }
  184. static byte getDirectionality(int ch) {
  185. int val = getProperties(ch);
  186. byte directionality = (byte)((val & 0x78000000) >> 27);
  187. if (directionality == 0xF ) {
  188. directionality = -1;
  189. }
  190. return directionality;
  191. }
  192. static boolean isMirrored(int ch) {
  193. int props = getProperties(ch);
  194. return ((props & 0x80000000) != 0);
  195. }
  196. static int toUpperCaseEx(int ch) {
  197. int mapChar = ch;
  198. int val = getProperties(ch);
  199. if ((val & 0x00010000) != 0) {
  200. if ((val & 0x07FC0000) != 0x07FC0000) {
  201. int offset = val << 5 >> (5+18);
  202. mapChar = ch - offset;
  203. }
  204. else {
  205. switch(ch) {
  206. // map overflow characters
  207. case 0x00B5 : mapChar = 0x039C; break;
  208. default : mapChar = Character.CHAR_ERROR; break;
  209. }
  210. }
  211. }
  212. return mapChar;
  213. }
  214. static char[] sharpsMap = new char[] {'S', 'S'};
  215. static char[] toUpperCaseCharArray(int ch) {
  216. char[] upperMap = {(char)ch};
  217. if (ch == 0x00DF) {
  218. upperMap = sharpsMap;
  219. }
  220. return upperMap;
  221. }
  222. // The following tables and code generated using:
  223. // java GenerateCharacter -template ../../tools/GenerateCharacter/CharacterDataLatin1.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/CharacterDataLatin1.java -string -usecharforbyte -latin1 8
  224. // The A table has 256 entries for a total of 1024 bytes.
  225. static final int A[] = new int[256];
  226. static final String A_DATA =
  227. "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
  228. "\u100F\u4800\u100F\u4800\u100F\u5800\u400F\u5000\u400F\u5800\u400F\u6000\u400F"+
  229. "\u5000\u400F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
  230. "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
  231. "\u4800\u100F\u4800\u100F\u5000\u400F\u5000\u400F\u5000\u400F\u5800\u400F\u6000"+
  232. "\u400C\u6800\030\u6800\030\u2800\030\u2800\u601A\u2800\030\u6800\030\u6800"+
  233. "\030\uE800\025\uE800\026\u6800\030\u2800\031\u3800\030\u2800\024\u3800\030"+
  234. "\u2000\030\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800"+
  235. "\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u1800\u3609\u3800\030\u6800\030"+
  236. "\uE800\031\u6800\031\uE800\031\u6800\030\u6800\030\202\u7FE1\202\u7FE1\202"+
  237. "\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1"+
  238. "\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202"+
  239. "\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1\202\u7FE1"+
  240. "\202\u7FE1\uE800\025\u6800\030\uE800\026\u6800\033\u6800\u5017\u6800\033\201"+
  241. "\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2"+
  242. "\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201"+
  243. "\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2\201\u7FE2"+
  244. "\201\u7FE2\201\u7FE2\201\u7FE2\uE800\025\u6800\031\uE800\026\u6800\031\u4800"+
  245. "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u5000\u100F"+
  246. "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
  247. "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
  248. "\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800"+
  249. "\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F\u4800\u100F"+
  250. "\u3800\014\u6800\030\u2800\u601A\u2800\u601A\u2800\u601A\u2800\u601A\u6800"+
  251. "\034\u6800\034\u6800\033\u6800\034\000\u7002\uE800\035\u6800\031\u6800\u1010"+
  252. "\u6800\034\u6800\033\u2800\034\u2800\031\u1800\u060B\u1800\u060B\u6800\033"+
  253. "\u07FD\u7002\u6800\034\u6800\030\u6800\033\u1800\u050B\000\u7002\uE800\036"+
  254. "\u6800\u080B\u6800\u080B\u6800\u080B\u6800\030\202\u7001\202\u7001\202\u7001"+
  255. "\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202"+
  256. "\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001"+
  257. "\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\u6800\031\202\u7001\202"+
  258. "\u7001\202\u7001\202\u7001\202\u7001\202\u7001\202\u7001\u07FD\u7002\201\u7002"+
  259. "\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201"+
  260. "\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002"+
  261. "\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\u6800"+
  262. "\031\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002\201\u7002"+
  263. "\u061D\u7002";
  264. // In all, the character property tables require 1024 bytes.
  265. static {
  266. { // THIS CODE WAS AUTOMATICALLY CREATED BY GenerateCharacter:
  267. char[] data = A_DATA.toCharArray();
  268. assert (data.length == (256 * 2));
  269. int i = 0, j = 0;
  270. while (i < (256 * 2)) {
  271. int entry = data[i++] << 16;
  272. A[j++] = entry | data[i++];
  273. }
  274. }
  275. }
  276. }