test/jdk/java/lang/Character/CharCheck.java
author rgoel
Tue, 08 May 2018 11:49:42 +0530
changeset 50045 d9d55f64d136
permissions -rw-r--r--
8191410: Unicode 10 Summary: upgrade to Unicode 10 Reviewed-by: naoto, rriggs, igerasim
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50045
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     1
/*
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     4
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    10
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    15
 * accompanied this code).
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    16
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    20
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    23
 * questions.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    24
 */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    25
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    26
/**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    27
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    28
 * @author Alan Liu
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    29
 * @author John O'Conner
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    30
 */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    31
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    32
import java.io.*;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    33
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    34
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    35
/**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    36
 * This class either loads or dumps the character properties of all Unicode
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    37
 * characters out to a file.  When loading, it compares the loaded data with
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    38
 * that obtained through the java.lang.Character API.  This allows detection of
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    39
 * changes to the character properties between versions of the Java VM.  A
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    40
 * typical usage would be to dump the properties under an early VM, and load
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    41
 * them under a later VM.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    42
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    43
 * Also: Check the current VM's character properties against those in a
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    44
 * Unicode database.  The database should be of the format
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    45
 * available on ftp.unicode.org/Public/UNIDATA.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    46
 *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    47
 */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    48
public class CharCheck {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    49
    static int differences = 0;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    50
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    51
    public static void main(String args[]) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    52
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    53
        if (args.length != 2 && args.length != 3) usage();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    54
        if (args[0].equals("dump"))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    55
           dump(Integer.parseInt(args[1], 16), new ObjectOutputStream(new FileOutputStream(args[2])));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    56
        else if (args[0].equals("load"))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    57
            load(Integer.parseInt(args[1], 16), new ObjectInputStream(new FileInputStream(args[2])));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    58
        else if (args[0].equals("check"))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    59
           check(Integer.parseInt(args[1], 16), new File(args[2]));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    60
        else if (args[0].equals("char"))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    61
            showChar(Integer.parseInt(args[1],16));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    62
        else if (args[0].equals("fchar"))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    63
            showFileChar(args[1], Integer.parseInt(args[2],16));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    64
        else usage();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    65
       if (differences != 0) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    66
            throw new RuntimeException("There are differences between Character properties and the specification.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    67
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    68
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    69
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    70
    static void usage() {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    71
        System.err.println("Usage: java CharCheck <command>");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    72
        System.err.println("where <command> is one of the following:");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    73
        System.err.println("dump <plane> <file> - dumps the character properties of the given plane,");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    74
                System.err.println("              read from the current VM, to the given file.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    75
        System.err.println("load <plane> <file> - loads the character properties from the given");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    76
        System.err.println("              file and compares them to those of the given character plane");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    77
                System.err.println("              in the current VM.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    78
        System.err.println("check <plane> <file> - compare the current VM's character properties");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    79
                System.err.println("               in the given plane to those listed in the given file, ");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    80
                System.err.println("               which should be in the format available on ");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    81
                System.err.println("               ftp.unicode.org/Public/2.0-Update.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    82
        System.err.println("char <code> - show current VM properties of the given Unicode char.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    83
        System.err.println("fchar <file> <code> - show file properties of the given Unicode char.");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    84
        System.exit(0);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    85
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    86
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    87
    static String getTypeName(int type) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    88
        return (type >= 0 && type < UnicodeSpec.generalCategoryList.length) ?
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    89
                        (UnicodeSpec.generalCategoryList[type][UnicodeSpec.LONG] + '(' + type + ')') :
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    90
                        ("<Illegal type value " + type + ">");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    91
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    92
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    93
    static int check(int plane, File specFile) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    94
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    95
        String version = System.getProperty("java.version");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    96
        System.out.println("Current VM version " + version);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    97
        int rangeLimit = (plane << 16) | 0xFFFF;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    98
        String record;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
    99
        UnicodeSpec[] spec = UnicodeSpec.readSpecFile(specFile, plane);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   100
        int rangeStart = 0x0000;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   101
        boolean isRange = false;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   102
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   103
        lastCheck = (plane << 16) - 1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   104
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   105
        for (int currentSpec = 0; currentSpec < spec.length; currentSpec++) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   106
            int c = spec[currentSpec].getCodePoint();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   107
            if (isRange) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   108
                // Must see end of range now
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   109
                if (spec[currentSpec].getName().endsWith("Last>")) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   110
                    for (int d=rangeStart; d<=c; d++)  {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   111
                        checkOneChar(d, spec[currentSpec]);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   112
                    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   113
                }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   114
                else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   115
                    // No good -- First without Last
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   116
                    System.out.println("BAD FILE: First without last at '" + escape(rangeStart) + "'");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   117
                }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   118
                isRange = false;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   119
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   120
            else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   121
                // Look for a First, Last pair: This is a pair of entries like the following:
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   122
                //  4E00;<CJK Ideograph, First>;Lo;0;L;;;;;N;;;;;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   123
                //  9FA5;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   124
                if (spec[currentSpec].getName().endsWith("First>")) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   125
                    rangeStart = c;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   126
                    isRange = true;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   127
                }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   128
                else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   129
                    checkOneChar(c, spec[currentSpec]);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   130
                }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   131
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   132
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   133
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   134
        // Check undefined chars at the end of the range
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   135
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   136
        while (lastCheck < rangeLimit) checkOneCharDefined(++lastCheck, "?", false);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   137
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   138
        System.out.println("Total differences: "+differences);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   139
        return differences;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   140
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   141
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   142
    static int lastCheck = -1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   143
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   144
    static final void checkOneCharDefined(int c, String name, boolean fileDefined) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   145
        if (Character.isDefined(c) != fileDefined)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   146
            showDifference(c, name, "isDefined", ""+(!fileDefined), ""+fileDefined);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   147
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   148
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   149
    // In GenerateCharacter, the following ranges are handled specially.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   150
    // Each is the start of a 26-character range with values 10..35.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   151
    static final char NUMERIC_EXCEPTION[] = { '\u0041', '\u0061', '\uFF21', '\uFF41' };
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   152
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   153
    static void checkOneChar(int c, UnicodeSpec charSpec) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   154
        // Handle intervening ranges -- we assume that we will be called in monotonically
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   155
        // increasing order.  If the last char we checked is more than one before this
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   156
        // char, then check the intervening range -- it should all be undefined.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   157
        int lowerLimit = (c & 0xFF0000);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   158
        if (lastCheck >= lowerLimit && (lastCheck+1) != c) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   159
            for (int i=lastCheck+1; i<c; ++i)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   160
                checkOneCharDefined(i, "?", false);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   161
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   162
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   163
        lastCheck = c;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   164
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   165
        // isDefined should be true
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   166
        checkOneCharDefined(c, charSpec.getName(), true);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   167
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   168
        // Check lower, upper, and titlecase conversion
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   169
        int upper = Character.toUpperCase(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   170
        int lower = Character.toLowerCase(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   171
        int title = Character.toTitleCase(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   172
        int upperDB = charSpec.hasUpperMap() ? charSpec.getUpperMap() : c;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   173
        int lowerDB = charSpec.hasLowerMap() ? charSpec.getLowerMap() : c;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   174
        int titleDB = charSpec.hasTitleMap() ? charSpec.getTitleMap() : c;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   175
        if (upper != upperDB) showDifference(c, charSpec.getName(), "upper", hex6(upper), hex6(upperDB));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   176
        if (lower != lowerDB) showDifference(c, charSpec.getName(), "lower", hex6(lower), hex6(lowerDB));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   177
        if (title != titleDB) showDifference(c, charSpec.getName(), "title", hex6(title), hex6(titleDB));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   178
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   179
        // Check the character general category (type)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   180
        int type = Character.getType(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   181
        int typeDB = charSpec.getGeneralCategory();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   182
        if (type != typeDB) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   183
            showDifference(c, charSpec.getName(), "type",
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   184
                UnicodeSpec.generalCategoryList[type][UnicodeSpec.SHORT],
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   185
                UnicodeSpec.generalCategoryList[typeDB][UnicodeSpec.SHORT]);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   186
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   187
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   188
        // Check the mirrored property
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   189
        boolean isMirrored = Character.isMirrored(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   190
        boolean isMirroredDB = charSpec.isMirrored();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   191
        if (isMirrored != isMirroredDB) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   192
                showDifference(c, charSpec.getName(), "isMirrored", ""+isMirrored, ""+isMirroredDB);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   193
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   194
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   195
        // Check the directionality property
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   196
        byte directionality = Character.getDirectionality(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   197
        byte directionalityDB = charSpec.getBidiCategory();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   198
        if (directionality != directionalityDB) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   199
            showDifference(c, charSpec.getName(), "directionality", ""+directionality, ""+directionalityDB);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   200
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   201
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   202
        // Check the decimal digit property
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   203
        int decimalDigit = Character.digit(c, 10);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   204
        int decimalDigitDB = -1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   205
        if (charSpec.getGeneralCategory() == UnicodeSpec.DECIMAL_DIGIT_NUMBER) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   206
            decimalDigitDB = charSpec.getDecimalValue();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   207
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   208
        if (decimalDigit != decimalDigitDB)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   209
            showDifference(c, charSpec.getName(), "decimal digit", ""+decimalDigit, ""+decimalDigitDB);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   210
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   211
        // Check the numeric property
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   212
        int numericValue = Character.getNumericValue(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   213
        int numericValueDB;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   214
        if (charSpec.getNumericValue().length() == 0) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   215
            numericValueDB = -1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   216
            // Handle exceptions where Character deviates from the UCS spec
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   217
            for (int k=0; k<NUMERIC_EXCEPTION.length; ++k) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   218
                if (c >= NUMERIC_EXCEPTION[k] && c < (char)(NUMERIC_EXCEPTION[k]+26)) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   219
                    numericValueDB = c - NUMERIC_EXCEPTION[k] + 10;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   220
                    break;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   221
                }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   222
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   223
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   224
        else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   225
            String strValue = charSpec.getNumericValue();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   226
            int parsedNumericValue;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   227
            if (strValue.equals("10000000000")
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   228
                || strValue.equals("1000000000000")) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   229
                System.out.println("Skipping strValue: " + strValue
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   230
                    + " for " + charSpec.getName()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   231
                    + "(0x" + Integer.toHexString(c) + ")");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   232
                parsedNumericValue = -2;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   233
            } else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   234
                parsedNumericValue = strValue.indexOf('/') < 0 ?
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   235
                                     Integer.parseInt(strValue) : -2;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   236
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   237
            numericValueDB = parsedNumericValue < 0 ? -2 : parsedNumericValue;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   238
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   239
        if (numericValue != numericValueDB)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   240
            showDifference(c, charSpec.getName(), "numeric value", ""+numericValue, ""+numericValueDB);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   241
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   242
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   243
    static void showDifference(int c, String name, String property, String vmValue, String dbValue) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   244
        System.out.println(escape("Mismatch at '" + hex6(c) + "' (" + name+ "): " +
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   245
                                         property + "=" + vmValue + ", db=" + dbValue));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   246
        ++differences;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   247
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   248
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   249
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   250
     * Given a record containing ';'-separated fields, return the fieldno-th
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   251
     * field.  The first field is field 0.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   252
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   253
    static String getField(String record, int fieldno) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   254
        int i=0;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   255
        int j=record.indexOf(';');
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   256
        while (fieldno > 0) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   257
            i=j+1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   258
            j=record.indexOf(';', i);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   259
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   260
        return record.substring(i, j);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   261
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   262
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   263
    static final int FIELD_COUNT = 15;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   264
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   265
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   266
     * Given a record containing ';'-separated fields, return an array of
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   267
     * the fields.  It is assumed that there are FIELD_COUNT fields per record.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   268
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   269
    static void getFields(String record, String[] fields) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   270
        int i=0;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   271
        int j=record.indexOf(';');
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   272
        fields[0] = record.substring(i, j);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   273
        for (int n=1; n<FIELD_COUNT; ++n) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   274
            i=j+1;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   275
            j=record.indexOf(';', i);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   276
            fields[n] = (j<0) ? record.substring(i) : record.substring(i, j);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   277
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   278
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   279
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   280
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   281
     * Given a record containing ';'-separated fields, return an array of
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   282
     * the fields.  It is assumed that there are FIELD_COUNT fields per record.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   283
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   284
    static String[] getFields(String record) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   285
        String[] fields = new String[FIELD_COUNT];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   286
        getFields(record, fields);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   287
        return fields;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   288
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   289
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   290
    static void dump(int plane, ObjectOutputStream out) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   291
        String version = System.getProperty("java.version");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   292
        System.out.println("Writing file version " + version);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   293
        out.writeObject(version);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   294
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   295
        long[] data = new long[0x20000];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   296
        long[] onechar = new long[2];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   297
        int j=0;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   298
        int begin = plane<<16;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   299
        int end = begin + 0xFFFF;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   300
        for (int i = begin; i <= end; ++i) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   301
            getPackedCharacterData(i, onechar);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   302
            data[j++] = onechar[0];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   303
            data[j++] = onechar[1];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   304
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   305
        out.writeObject(data);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   306
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   307
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   308
    static long[] loadData(ObjectInputStream in) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   309
        String version = System.getProperty("java.version");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   310
        String inVersion = (String)in.readObject();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   311
        System.out.println("Reading file version " + inVersion);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   312
        System.out.println("Current version " + version);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   313
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   314
        long[] data = (long[])in.readObject();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   315
        if (data.length != 0x20000) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   316
            System.out.println("BAD ARRAY LENGTH: " + data.length);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   317
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   318
        return data;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   319
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   320
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   321
    static int load(int plane, ObjectInputStream in) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   322
        long[] data = CharCheck.loadData(in);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   323
        CharCheck.checkData(data, plane);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   324
        return differences;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   325
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   326
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   327
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   328
    static int checkData(long[] data, int plane) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   329
        long[] onechar = new long[2];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   330
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   331
        for (int i=0; i<0x10000; ++i) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   332
            int c = (plane << 16) | i;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   333
            getPackedCharacterData(c, onechar);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   334
            if (data[2*i] != onechar[0] || data[2*i+1] != onechar[1]) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   335
                long[] filechar = { data[2*i], data[2*i+1] };
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   336
                showDifference(c, onechar, filechar);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   337
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   338
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   339
        System.out.println("Total differences: " + differences);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   340
        return differences;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   341
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   342
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   343
    static String hex6(long n) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   344
        String q = Long.toHexString(n).toUpperCase();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   345
        return "000000".substring(Math.min(6, q.length())) + q;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   346
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   347
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   348
    static void showChar(int c) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   349
        long[] chardata = new long[2];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   350
        getPackedCharacterData(c, chardata);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   351
        System.out.println("Current VM properties for '" + hex6(c) + "': " +
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   352
                           hex6(chardata[1]) + ' ' + hex6(chardata[0]));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   353
        String[] data = unpackCharacterData(chardata);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   354
        for (int i=0; i<data.length; ++i)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   355
            System.out.println(" " + escape(data[i]));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   356
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   357
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   358
    static void showFileChar(String fileName, int c) throws Exception {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   359
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   360
        String inVersion = (String)in.readObject();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   361
        System.out.println("Reading file version " + inVersion);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   362
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   363
        long[] data = (long[])in.readObject();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   364
        if (data.length != 0x20000) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   365
            System.out.println("BAD ARRAY LENGTH: " + data.length);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   366
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   367
        int offset = c & 0xFFFF;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   368
        long[] chardata = { data[2*offset], data[2*offset+1] };
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   369
        String[] datap = unpackCharacterData(chardata);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   370
        System.out.println(escape("File properties for '" + hex6(c)+ "':"));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   371
        for (int i=0; i<datap.length; ++i)
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   372
            System.out.println(" " + escape(datap[i]));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   373
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   374
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   375
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   376
     * The packed character data encapsulates all the information obtainable
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   377
     * about a character in a single numeric value.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   378
     *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   379
     * data[0]:
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   380
     *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   381
     *  5 bits for getType()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   382
     *  6 bits for digit() -- add one
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   383
     *  6 bits for getNumericValue() -- add two
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   384
     * 15 bits for isXxx()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   385
     *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   386
     * 21 bits for toUpperCase()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   387
     *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   388
     *
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   389
     * data[1]:
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   390
     * 21 bits for toLowerCase()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   391
     * 21 bits for toTitleCase()
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   392
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   393
    static void getPackedCharacterData(int c, long[] data) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   394
        data[0] =
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   395
            (long)Character.getType(c) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   396
            ((long)(Character.digit(c, Character.MAX_RADIX) + 1) << 5) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   397
            ((long)(Character.getNumericValue(c) + 2) << 11) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   398
            (Character.isDefined(c) ? (1L<<17) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   399
            (Character.isDigit(c) ? (1L<<18) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   400
            (Character.isIdentifierIgnorable(c) ? (1L<<19) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   401
            (Character.isISOControl(c) ? (1L<<20) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   402
            (Character.isJavaIdentifierPart(c) ? (1L<<21) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   403
            (Character.isJavaIdentifierStart(c) ? (1L<<22) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   404
            (Character.isLetter(c) ? (1L<<23) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   405
            (Character.isLetterOrDigit(c) ? (1L<<24) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   406
            (Character.isLowerCase(c) ? (1L<<25) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   407
            (Character.isSpaceChar(c) ? (1L<<26) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   408
            (Character.isTitleCase(c) ? (1L<<27) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   409
            (Character.isUnicodeIdentifierPart(c) ? (1L<<28) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   410
            (Character.isUnicodeIdentifierStart(c) ? (1L<<29) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   411
            (Character.isUpperCase(c) ? (1L<<30) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   412
            (Character.isWhitespace(c) ? (1L<<31) : 0L) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   413
            ((long)Character.toUpperCase(c) << 32);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   414
        data[1] = (long)Character.toLowerCase(c) |
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   415
                        ((long)Character.toTitleCase(c) << 21);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   416
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   417
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   418
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   419
     * Given a long, set the bits at the given offset and length to the given value.
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   420
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   421
    static long setBits(long data, int offset, int length, long value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   422
        long himask = -1L << (offset+length);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   423
        long lomask = ~(-1L << offset);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   424
        long lengthmask = ~(-1L << length);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   425
        return (data & (himask | lomask)) | ((value & lengthmask) << offset);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   426
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   427
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   428
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   429
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   430
     * toLower
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   431
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   432
    static void setToLower(long[] data, int value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   433
        data[0] = setBits(data[0], 48, 16, value);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   434
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   435
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   436
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   437
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   438
     * toUpper
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   439
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   440
    static void setToUpper(long[] data, int value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   441
        data[0] = setBits(data[0], 32, 16, value);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   442
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   443
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   444
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   445
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   446
     * toTitle
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   447
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   448
    static void setToTitle(long[] data, int value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   449
        data[1] = value;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   450
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   451
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   452
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   453
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   454
     * getType
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   455
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   456
    static void setGetType(long[] data, int value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   457
        data[0] = setBits(data[0], 0, 5, value);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   458
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   459
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   460
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   461
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   462
     * isDefined
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   463
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   464
    static void setIsDefined(long[] data, boolean value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   465
        data[0] = setBits(data[0], 17, 1, value?1:0);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   466
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   467
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   468
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   469
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   470
     * isJavaIdentifierPart
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   471
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   472
    static void setIsJavaIdentifierPart(long[] data, boolean value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   473
        data[0] = setBits(data[0], 21, 1, value?1:0);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   474
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   475
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   476
    /**
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   477
     * Given packed character data, change the attribute
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   478
     * isJavaIdentifierStart
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   479
     */
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   480
    static void setIsJavaIdentifierStart(long[] data, boolean value) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   481
        data[0] = setBits(data[0], 22, 1, value?1:0);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   482
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   483
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   484
    static String[] unpackCharacterData(long[] dataL) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   485
        long data = dataL[0];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   486
        String[] result = {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   487
            "type=" + getTypeName((int)(data&0x1F)),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   488
            "digit=" + (((data>>5)&0x3F)-1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   489
            "numeric=" + (((data>>11)&0x3F)-2),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   490
            "isDefined=" + (((data>>17)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   491
            "isDigit=" + (((data>>18)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   492
            "isIdentifierIgnorable=" + (((data>>19)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   493
            "isISOControl=" + (((data>>20)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   494
            "isJavaIdentifierPart=" + (((data>>21)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   495
            "isJavaIdentifierStart=" + (((data>>22)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   496
            "isLetter=" + (((data>>23)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   497
            "isLetterOrDigit=" + (((data>>24)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   498
            "isLowerCase=" + (((data>>25)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   499
            "isSpaceChar=" + (((data>>26)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   500
            "isTitleCase=" + (((data>>27)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   501
            "isUnicodeIdentifierPart=" + (((data>>28)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   502
            "isUnicodeIdentifierStart=" + (((data>>29)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   503
            "isUpperCase=" + (((data>>30)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   504
            "isWhitespace=" + (((data>>31)&1)==1),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   505
            "toUpper=" + hex6(((int)(data>>32) & 0X1FFFFF)),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   506
            "toLower=" + hex6((int)(dataL[1] & 0x1FFFFF)),
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   507
                        "toTitle=" + hex6(((int)(dataL[1] >> 21) & 0x1FFFFF))
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   508
        };
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   509
        return result;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   510
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   511
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   512
    static String[] getCharacterData(int c) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   513
        long[] data = new long[2];
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   514
        getPackedCharacterData(c, data);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   515
        return unpackCharacterData(data);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   516
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   517
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   518
    static void showDifference(int c, long[] currentData, long[] fileData) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   519
        System.out.println("Difference at " + hex6(c));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   520
        String[] current = unpackCharacterData(currentData);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   521
        String[] file = unpackCharacterData(fileData);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   522
        for (int i=0; i<current.length; ++i) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   523
            if (!current[i].equals(file[i])) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   524
                System.out.println(escape(" current " + current[i] +
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   525
                                   ", file " + file[i]));
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   526
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   527
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   528
        ++differences;
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   529
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   530
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   531
    static String escape(String s) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   532
        StringBuffer buf = new StringBuffer();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   533
        for (int i=0; i<s.length(); ++i) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   534
            char c = s.charAt(i);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   535
            if (c >= 0x20 && c <= 0x7F) buf.append(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   536
            else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   537
                buf.append("\\u");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   538
                String h = "000" + Integer.toHexString(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   539
                if (h.length() > 4) h = h.substring(h.length() - 4);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   540
                buf.append(h);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   541
            }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   542
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   543
        return buf.toString();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   544
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   545
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   546
    static String escape(int c) {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   547
        StringBuffer buf = new StringBuffer();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   548
        if (c >= 0x20 && c <= 0x7F) buf.append(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   549
        else {
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   550
            buf.append("\\u");
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   551
            String h = "000" + Integer.toHexString(c);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   552
            if (h.length() > 4) h = h.substring(h.length() - 4);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   553
            buf.append(h);
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   554
        }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   555
        return buf.toString();
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   556
    }
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   557
}
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   558
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   559
d9d55f64d136 8191410: Unicode 10
rgoel
parents:
diff changeset
   560
//eof