1 /* |
1 /* |
2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
175 } |
175 } |
176 if (ch == map[current].getCharSource()) return current; |
176 if (ch == map[current].getCharSource()) return current; |
177 else return -1; |
177 else return -1; |
178 } |
178 } |
179 |
179 |
180 /* |
180 /* |
181 * Extracts and returns the high surrogate value from a UTF-32 code point. |
181 * Extracts and returns the high surrogate value from a UTF-32 code point. |
182 * If argument is a BMP character, then it is converted to a char and returned; |
182 * If argument is a BMP character, then it is converted to a char and returned; |
183 * otherwise the high surrogate value is extracted. |
183 * otherwise the high surrogate value is extracted. |
184 * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF. |
184 * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF. |
185 * @return the high surrogate value that helps create <code>codePoint</code>; else |
185 * @return the high surrogate value that helps create <code>codePoint</code>; else |
186 * the char representation of <code>codePoint</code> if it is a BMP character. |
186 * the char representation of <code>codePoint</code> if it is a BMP character. |
187 * @since 1.5 |
187 * @since 1.5 |
188 */ |
188 */ |
189 static char getHighSurrogate(int codePoint) { |
189 static char getHighSurrogate(int codePoint) { |
190 char high = (char)codePoint; |
190 char high = (char)codePoint; |
191 if (codePoint > 0xFFFF) { |
191 if (codePoint > 0xFFFF) { |
192 high = (char)((codePoint - 0x10000)/0x0400 + 0xD800); |
192 high = (char)((codePoint - 0x10000)/0x0400 + 0xD800); |
193 } |
193 } |
194 return high; |
194 return high; |
195 } |
195 } |
196 |
196 |
197 |
197 |
198 /* |
198 /* |
199 * Extracts and returns the low surrogate value from a UTF-32 code point. |
199 * Extracts and returns the low surrogate value from a UTF-32 code point. |
200 * If argument is a BMP character, then it is converted to a char and returned; |
200 * If argument is a BMP character, then it is converted to a char and returned; |
201 * otherwise the high surrogate value is extracted. |
201 * otherwise the high surrogate value is extracted. |
202 * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF. |
202 * @param codePoint a UTF-32 codePoint with value greater than 0xFFFF. |
203 * @return the low surrogate value that helps create <code>codePoint</code>; else |
203 * @return the low surrogate value that helps create <code>codePoint</code>; else |
204 * the char representation of <code>codePoint</code> if it is a BMP character. |
204 * the char representation of <code>codePoint</code> if it is a BMP character. |
205 * @since 1.5 |
205 * @since 1.5 |
206 */ |
206 */ |
207 static char getLowSurrogate(int codePoint) { |
207 static char getLowSurrogate(int codePoint) { |
208 char low = (char)codePoint; |
208 char low = (char)codePoint; |
209 if(codePoint > 0xFFFF) { |
209 if(codePoint > 0xFFFF) { |
210 low = (char)((codePoint - 0x10000)%0x0400 + 0xDC00); |
210 low = (char)((codePoint - 0x10000)%0x0400 + 0xDC00); |
211 } |
211 } |
212 return low; |
212 return low; |
213 } |
213 } |
214 |
214 |
215 static String hex6(int n) { |
215 static String hex6(int n) { |
216 String str = Integer.toHexString(n & 0xFFFFFF).toUpperCase(); |
216 String str = Integer.toHexString(n & 0xFFFFFF).toUpperCase(); |
217 return "000000".substring(Math.min(6, str.length())) + str; |
217 return "000000".substring(Math.min(6, str.length())) + str; |
218 |
218 } |
219 } |
219 |
220 |
220 static String hex6(char[] map){ |
221 static String hex6(char[] map){ |
221 StringBuffer buff = new StringBuffer(); |
222 StringBuffer buff = new StringBuffer(); |
222 int x=0; |
223 int x=0; |
223 buff.append(hex6(map[x++])); |
224 buff.append(hex6(map[x++])); |
224 while(x<map.length) { |
225 while(x<map.length) { |
225 buff.append(" " + hex6(map[x++])); |
226 buff.append(" " + hex6(map[x++])); |
226 } |
227 } |
227 return buff.toString(); |
228 return buff.toString(); |
228 } |
229 } |
|
230 |
229 |
231 void setCharSource(int ch) { |
230 void setCharSource(int ch) { |
232 chSource = ch; |
231 chSource = ch; |
233 } |
232 } |
234 |
233 |
300 static String CONTEXT_FINAL = "FINAL"; |
299 static String CONTEXT_FINAL = "FINAL"; |
301 static String CONTEXT_NONFINAL = "NON_FINAL"; |
300 static String CONTEXT_NONFINAL = "NON_FINAL"; |
302 static String CONTEXT_MODERN = "MODERN"; |
301 static String CONTEXT_MODERN = "MODERN"; |
303 static String CONTEXT_NONMODERN = "NON_MODERN"; |
302 static String CONTEXT_NONMODERN = "NON_MODERN"; |
304 |
303 |
305 public int compareTo(Object otherObject) { |
304 public int compareTo(SpecialCaseMap otherObject) { |
306 SpecialCaseMap other = (SpecialCaseMap)otherObject; |
305 if (chSource < otherObject.chSource) { |
307 if (chSource < other.chSource) { |
|
308 return -1; |
306 return -1; |
309 } |
307 } |
310 else if (chSource > other.chSource) { |
308 else if (chSource > otherObject.chSource) { |
311 return 1; |
309 return 1; |
312 } |
310 } |
313 else return 0; |
311 else return 0; |
314 } |
312 } |
315 |
313 |
316 public boolean equals(Object o1) { |
314 public boolean equals(Object o1) { |
317 boolean bEqual = false; |
315 if (this == o1) { |
318 if (0 == compareTo(o1)) { |
316 return true; |
319 bEqual = true; |
317 } |
|
318 if (o1 == null || !(o1 instanceof SpecialCaseMap)) { |
|
319 return false; |
|
320 } |
|
321 SpecialCaseMap other = (SpecialCaseMap)o1; |
|
322 boolean bEqual = false; |
|
323 if (0 == compareTo(other)) { |
|
324 bEqual = true; |
|
325 } |
|
326 return bEqual; |
|
327 } |
|
328 |
|
329 public String toString() { |
|
330 StringBuffer buff = new StringBuffer(); |
|
331 buff.append(hex6(getCharSource())); |
|
332 buff.append("|" + hex6(lowerCaseMap)); |
|
333 buff.append("|" + hex6(upperCaseMap)); |
|
334 buff.append("|" + hex6(titleCaseMap)); |
|
335 buff.append("|" + context); |
|
336 return buff.toString(); |
|
337 } |
|
338 |
|
339 public int hashCode() { |
|
340 return chSource; |
|
341 } |
|
342 |
|
343 public static void main(String[] args) { |
|
344 SpecialCaseMap[] spec = null; |
|
345 if (args.length == 2 ) { |
|
346 try { |
|
347 File file = new File(args[0]); |
|
348 int plane = Integer.parseInt(args[1]); |
|
349 spec = SpecialCaseMap.readSpecFile(file, plane); |
|
350 System.out.println("SpecialCaseMap[" + spec.length + "]:"); |
|
351 for (int x=0; x<spec.length; x++) { |
|
352 System.out.println(spec[x].toString()); |
320 } |
353 } |
321 return bEqual; |
354 } |
322 } |
355 catch(Exception e) { |
323 |
356 e.printStackTrace(); |
324 public String toString() { |
357 } |
325 StringBuffer buff = new StringBuffer(); |
358 } |
326 buff.append(hex6(getCharSource())); |
359 |
327 buff.append("|" + hex6(lowerCaseMap)); |
360 } |
328 buff.append("|" + hex6(upperCaseMap)); |
|
329 buff.append("|" + hex6(titleCaseMap)); |
|
330 buff.append("|" + context); |
|
331 return buff.toString(); |
|
332 } |
|
333 |
|
334 public int hashCode() { |
|
335 return (int)chSource; |
|
336 } |
|
337 |
|
338 public static void main(String[] args) { |
|
339 SpecialCaseMap[] spec = null; |
|
340 if (args.length == 2 ) { |
|
341 try { |
|
342 File file = new File(args[0]); |
|
343 int plane = Integer.parseInt(args[1]); |
|
344 spec = SpecialCaseMap.readSpecFile(file, plane); |
|
345 System.out.println("SpecialCaseMap[" + spec.length + "]:"); |
|
346 for (int x=0; x<spec.length; x++) { |
|
347 System.out.println(spec[x].toString()); |
|
348 } |
|
349 } |
|
350 catch(Exception e) { |
|
351 e.printStackTrace(); |
|
352 } |
|
353 } |
|
354 |
|
355 } |
|
356 |
361 |
357 } |
362 } |