1 /* 2 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 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 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 /** 26 * @test 27 * @bug 7037261 7070436 7198195 8032446 8072600 8221431 28 * @summary Check j.l.Character.isLowerCase/isUppercase/isAlphabetic/isIdeographic 29 * @library /lib/testlibrary/java/lang 30 */ 31 32 import java.util.regex.*; 33 import java.util.*; 34 import java.io.*; 35 import static java.lang.Character.*; 36 37 public class CheckProp { 38 39 public static void main(String[] args) throws IOException { 40 File fPropList = UCDFiles.PROP_LIST.toFile(); 41 int i, j; 42 BufferedReader sbfr = new BufferedReader(new FileReader(fPropList)); 43 Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher(""); 44 Map<String, ArrayList<Integer>> propMap = new LinkedHashMap<>(); 45 46 String line = null; 47 int lineNo = 0; 48 while ((line = sbfr.readLine()) != null) { 49 lineNo++; 50 if (line.length() <= 1 || line.charAt(0) == '#') { 51 continue; 52 } 53 m.reset(line); 54 if (m.matches()) { 55 int start = Integer.parseInt(m.group(1), 16); 56 int end = (m.group(2)==null)?start 57 :Integer.parseInt(m.group(2), 16); 58 String name = m.group(3); 59 60 ArrayList<Integer> list = propMap.get(name); 61 if (list == null) { 62 list = new ArrayList<Integer>(); 63 propMap.put(name, list); 64 } 65 while (start <= end) 66 list.add(start++); 67 } else { 68 System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line); 69 } 70 } 71 sbfr.close(); 72 //for (String name: propMap.keySet()) { 73 // System.out.printf("%s %d%n", name, propMap.get(name).size()); 74 //} 75 76 Integer[] otherLowercase = propMap.get("Other_Lowercase").toArray(new Integer[0]); 77 Integer[] otherUppercase = propMap.get("Other_Uppercase").toArray(new Integer[0]); 78 Integer[] otherAlphabetic = propMap.get("Other_Alphabetic").toArray(new Integer[0]); 79 Integer[] ideographic = propMap.get("Ideographic").toArray(new Integer[0]); 80 81 int fails = 0; 82 for (int cp = MIN_CODE_POINT; cp < MAX_CODE_POINT; cp++) { 83 int type = getType(cp); 84 if (isLowerCase(cp) != 85 (type == LOWERCASE_LETTER || 86 Arrays.binarySearch(otherLowercase, cp) >= 0)) 87 { 88 fails++; 89 System.err.printf("Wrong isLowerCase(U+%04x)\n", cp); 90 } 91 if (isUpperCase(cp) != 92 (type == UPPERCASE_LETTER || 93 Arrays.binarySearch(otherUppercase, cp) >= 0)) 94 { 95 fails++; 96 System.err.printf("Wrong isUpperCase(U+%04x)\n", cp); 97 } 98 if (isAlphabetic(cp) != 99 (type == UPPERCASE_LETTER || type == LOWERCASE_LETTER || 100 type == TITLECASE_LETTER || type == MODIFIER_LETTER || 101 type == OTHER_LETTER || type == OTHER_LETTER || 102 type == LETTER_NUMBER || 103 Arrays.binarySearch(otherAlphabetic, cp) >=0)) 104 { 105 fails++; 106 System.err.printf("Wrong isAlphabetic(U+%04x)\n", cp); 107 } 108 if (isIdeographic(cp) != 109 (Arrays.binarySearch(ideographic, cp) >= 0)) 110 { 111 fails++; 112 System.err.printf("Wrong isIdeographic(U+%04x)\n", cp); 113 } 114 } 115 if (fails != 0) 116 throw new RuntimeException("CheckProp failed=" + fails); 117 } 118 }