jdk/make/src/classes/build/tools/generatecharacter/PropList.java
author lana
Thu, 26 Dec 2013 12:04:16 -0800
changeset 23010 6dadb192ad81
parent 21805 c7d7946239de
permissions -rw-r--r--
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013 Summary: updated files with 2011, 2012 and 2013 years according to the file's last updated date Reviewed-by: tbell, lancea, chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21805
diff changeset
     2
 * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
9535
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     4
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    10
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    15
 * accompanied this code).
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    16
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    20
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    23
 * questions.
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    24
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    25
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    26
package build.tools.generatecharacter;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    27
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    28
import java.util.regex.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    29
import java.util.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    30
import java.io.*;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    31
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    32
/**
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    33
 * A PropList object contains the lists of code points that have
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    34
 * the same Unicode property defined in PropList.txt
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    35
 *
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    36
 * @author Xueming Shen
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    37
 */
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    38
public class PropList {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    39
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    40
    public static PropList readSpecFile(File file, int plane)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    41
        throws IOException
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    42
    {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    43
        return new PropList(file, plane);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    44
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    45
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    46
    public List<Integer> codepoints(String name) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    47
        return propMap.get(name);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    48
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    49
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    50
    public Set<String> names() {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    51
        return propMap.keySet();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    52
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    53
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    54
    private Map<String, ArrayList<Integer>> propMap =
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    55
        new LinkedHashMap<String, ArrayList<Integer>>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    56
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    57
    private PropList(File file, int plane) throws IOException {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    58
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    59
        int i, j;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    60
        BufferedReader sbfr = new BufferedReader(new FileReader(file));
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    61
        Matcher m = Pattern.compile("(\\p{XDigit}+)(?:\\.{2}(\\p{XDigit}+))?\\s*;\\s+(\\w+)\\s+#.*").matcher("");
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    62
        String line = null;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    63
        int lineNo = 0;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    64
        while ((line = sbfr.readLine()) != null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    65
            lineNo++;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    66
            if (line.length() <= 1 || line.charAt(0) == '#') {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    67
                continue;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    68
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    69
            m.reset(line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    70
            if (m.matches()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    71
                int start = Integer.parseInt(m.group(1), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    72
                if ((start >> 16) != plane)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    73
                    continue;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    74
                int end = (m.group(2)==null)?start
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    75
                          :Integer.parseInt(m.group(2), 16);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    76
                String name = m.group(3);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    77
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    78
                start &= 0xffff;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    79
                end &= 0xffff;
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    80
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    81
                ArrayList<Integer> list = propMap.get(name);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    82
                if (list == null) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    83
                    list = new ArrayList<Integer>();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    84
                    propMap.put(name, list);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    85
                }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    86
                while (start <= end)
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    87
                    list.add(start++);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    88
            } else {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    89
                System.out.printf("Warning: Unrecognized line %d <%s>%n", lineNo, line);
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    90
            }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    91
        }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    92
        sbfr.close();
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    93
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    94
        //for (String name: propMap.keySet()) {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    95
        //    System.out.printf("%s    %d%n", name, propMap.get(name).size());
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    96
        //}
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    97
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    98
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
    99
    public static void main(String[] args) throws IOException {
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   100
        readSpecFile(new File(args[0]), Integer.decode(args[1]));
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   101
    }
d930011fd275 7037261: j.l.Character.isLowerCase/isUpperCase need to match the Unicode Standard
sherman
parents:
diff changeset
   102
}