1 /* 2 * Copyright (c) 2011, 2013, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package build.tools.generatecharacter; 27 28 import java.util.regex.*; 29 import java.util.*; 30 import java.io.*; 31 32 /** 33 * A PropList object contains the lists of code points that have 34 * the same Unicode property defined in PropList.txt 35 * 36 * @author Xueming Shen 37 */ 38 public class PropList { 39 40 public static PropList readSpecFile(File file, int plane) 41 throws IOException 42 { 43 return new PropList(file, plane); 44 } 45 46 public List<Integer> codepoints(String name) { 47 return propMap.get(name); 48 } 49 50 public Set<String> names() { 51 return propMap.keySet(); 52 } 53 54 private Map<String, ArrayList<Integer>> propMap = 55 new LinkedHashMap<String, ArrayList<Integer>>(); 56 57 private PropList(File file, int plane) throws IOException { 58 59 int i, j; 60 BufferedReader sbfr = new BufferedReader(new FileReader(file)); 61 Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher(""); 62 String line = null; 63 int lineNo = 0; 64 while ((line = sbfr.readLine()) != null) { 65 lineNo++; 66 if (line.length() <= 1 || line.charAt(0) == '#') { 67 continue; 68 } 69 m.reset(line); 70 if (m.matches()) { 71 int start = Integer.parseInt(m.group(1), 16); 72 if ((start >> 16) != plane) 73 continue; 74 int end = (m.group(2)==null)?start 75 :Integer.parseInt(m.group(2), 16); 76 String name = m.group(3); 77 78 start &= 0xffff; 79 end &= 0xffff; 80 81 ArrayList<Integer> list = propMap.get(name); 82 if (list == null) { 83 list = new ArrayList<Integer>(); 84 propMap.put(name, list); 85 } 86 while (start <= end) 87 list.add(start++); 88 } else { 89 System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line); 90 } 91 } 92 sbfr.close(); 93 94 //for (String name: propMap.keySet()) { 95 // System.out.printf("%s %d%n", name, propMap.get(name).size()); 96 //} 97 } 98 99 public static void main(String[] args) throws IOException { 100 readSpecFile(new File(args[0]), Integer.decode(args[1])); 101 } 102 }