make/jdk/src/classes/build/tools/generatecharacter/UnicodeSpec.java
author pliden
Thu, 26 Sep 2019 13:56:58 +0200
changeset 58355 de246fd65587
parent 47216 71c04702a3d5
permissions -rw-r--r--
8231294: ZGC: vmTestbase/nsk/jvmti/ResourceExhausted/resexhausted002 fails Reviewed-by: shade, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package build.tools.generatecharacter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The UnicodeSpec class provides a way to read in Unicode character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * properties from a Unicode data file.  One instance of class UnicodeSpec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * holds a decoded version of one line of the data file.  The file may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * be obtained from www.unicode.org.  The method readSpecFile returns an array
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * of UnicodeSpec objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author      Guy Steele
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author  John O'Conner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class UnicodeSpec {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static final int MAP_UNDEFINED = 0xFFFFFFFF;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * Construct a default UnicodeSpec object, with a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * code point value 0xFFFF.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public UnicodeSpec() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                this(0xffff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         * Construct a UnicodeSpec object for the given <code>codePoint<code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
         * argument. Provide default properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
         * @param codePoint a Unicode code point between 0x0000 and 0x10FFFF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public UnicodeSpec(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.codePoint = codePoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        generalCategory = UNASSIGNED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        bidiCategory = DIRECTIONALITY_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        mirrored = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        titleMap = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        upperMap = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        lowerMap = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        decimalValue = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        digitValue = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        numericValue = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                oldName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                comment = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
         * Create a String representation of this UnicodeSpec object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
         * The string will contain the code point and all its case mappings
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
         * if available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        StringBuffer result = new StringBuffer(hex6(codePoint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (getUpperMap() != MAP_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            result.append(", upper=").append(hex6(upperMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (getLowerMap() != MAP_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            result.append(", lower=").append(hex6(lowerMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (getTitleMap() != MAP_UNDEFINED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            result.append(", title=").append(hex6(titleMap));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    static String hex4(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        String q = Integer.toHexString(n & 0xFFFF).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        return "0000".substring(Math.min(4, q.length())) + q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        static String hex6(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                String str = Integer.toHexString(n & 0xFFFFFF).toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                return "000000".substring(Math.min(6, str.length())) + str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    * Given one line of a Unicode data file as a String, parse the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    * and return a UnicodeSpec object that contains the same character information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    * @param s a line of the Unicode data file to be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    * @return a UnicodeSpec object, or null if the parsing process failed for some reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static UnicodeSpec parse(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        UnicodeSpec spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        String[] tokens = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        try {
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   124
            tokens = tokenSeparator.split(s, REQUIRED_FIELDS);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            spec = new UnicodeSpec();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            spec.setCodePoint(parseCodePoint(tokens[FIELD_VALUE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            spec.setName(parseName(tokens[FIELD_NAME]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            spec.setGeneralCategory(parseGeneralCategory(tokens[FIELD_CATEGORY]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            spec.setBidiCategory(parseBidiCategory(tokens[FIELD_BIDI]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            spec.setCombiningClass(parseCombiningClass(tokens[FIELD_CLASS]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            spec.setDecomposition(parseDecomposition(tokens[FIELD_DECOMPOSITION]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            spec.setDecimalValue(parseDecimalValue(tokens[FIELD_DECIMAL]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            spec.setDigitValue(parseDigitValue(tokens[FIELD_DIGIT]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            spec.setNumericValue(parseNumericValue(tokens[FIELD_NUMERIC]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            spec.setMirrored(parseMirrored(tokens[FIELD_MIRRORED]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            spec.setOldName(parseOldName(tokens[FIELD_OLDNAME]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            spec.setComment(parseComment(tokens[FIELD_COMMENT]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            spec.setUpperMap(parseUpperMap(tokens[FIELD_UPPERCASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            spec.setLowerMap(parseLowerMap(tokens[FIELD_LOWERCASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            spec.setTitleMap(parseTitleMap(tokens[FIELD_TITLECASE]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            System.out.println("Error parsing spec line.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        return spec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    * Parse the codePoint attribute for a Unicode character.  If the parse succeeds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    * the codePoint field of this UnicodeSpec object is updated and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    * The codePoint attribute should be a four to six digit hexadecimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    * @param s   the codePoint attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    * @return   code point if successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    * @exception NumberFormatException if unable to parse argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static int parseCodePoint(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return Integer.parseInt(s, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static String parseName(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (s==null) throw new Exception("Cannot parse name.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static byte parseGeneralCategory(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        byte category = GENERAL_CATEGORY_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        for (byte x=0; x<generalCategoryList.length; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            if (s.equals(generalCategoryList[x][SHORT])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                category = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (category >= GENERAL_CATEGORY_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new Exception("Could not parse general category.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return category;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static byte parseBidiCategory(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        byte category = DIRECTIONALITY_CATEGORY_COUNT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        for (byte x=0; x<bidiCategoryList.length; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (s.equals(bidiCategoryList[x][SHORT])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                category = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (category >= DIRECTIONALITY_CATEGORY_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new Exception("Could not parse bidi category.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return category;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    * Parse the combining attribute for a Unicode character.  If there is a combining
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    * attribute and the parse succeeds, then the hasCombining field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    * the combining field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    * If the combining attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    * hasCombining field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    * The combining attribute, if any, should be a nonnegative decimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    * @param s   the combining attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    * @return   the combining class value if any, -1 if property not defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    * @exception Exception if can't parse the combining class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public static int parseCombiningClass(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int combining = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (s.length()>0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            combining = Integer.parseInt(s, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return combining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    * Parse the decomposition attribute for a Unicode character.  If the parse succeeds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    * the decomposition field of this UnicodeSpec object is updated and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    * The decomposition attribute is complicated; for now, it is treated as a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    * @param s   the decomposition attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    * @return   true if the parse failed; otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public static String parseDecomposition(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (s==null) throw new Exception("Cannot parse decomposition.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    * Parse the decimal value attribute for a Unicode character.  If there is a decimal value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    * attribute and the parse succeeds, then the hasDecimalValue field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    * the decimalValue field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    * If the decimal value attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    * hasDecimalValue field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    * The decimal value attribute, if any, should be a nonnegative decimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    * @param s   the decimal value attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    * @return   the decimal value as an int, -1 if no decimal value defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    * @exception NumberFormatException if the parse fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public static int parseDecimalValue(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        int value = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (s.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            value = Integer.parseInt(s, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    * Parse the digit value attribute for a Unicode character.  If there is a digit value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    * attribute and the parse succeeds, then the hasDigitValue field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    * the digitValue field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    * If the digit value attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    * hasDigitValue field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    * The digit value attribute, if any, should be a nonnegative decimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    * @param s   the digit value attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    * @return   the digit value as an non-negative int, or -1 if no digit property defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    * @exception NumberFormatException if the parse fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public static int parseDigitValue(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int value = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (s.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            value = Integer.parseInt(s, 10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public static String parseNumericValue(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (s == null) throw new Exception("Cannot parse numeric value.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public static String parseComment(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if (s == null) throw new Exception("Cannot parse comment.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public static boolean parseMirrored(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        boolean mirrored;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (s.length() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (s.charAt(0) == 'Y') {mirrored = true;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            else if (s.charAt(0) == 'N') {mirrored = false;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            else {throw new Exception("Cannot parse mirrored property.");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        else { throw new Exception("Cannot parse mirrored property.");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return mirrored;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public static String parseOldName(String s) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (s == null) throw new Exception("Cannot parse old name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    * Parse the uppercase mapping attribute for a Unicode character.  If there is a uppercase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    * mapping attribute and the parse succeeds, then the hasUpperMap field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    * the upperMap field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    * If the uppercase mapping attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    * hasUpperMap field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    * The uppercase mapping attribute should be a four to six digit hexadecimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    * @param s   the uppercase mapping attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    * @return   simple uppercase character mapping if defined, MAP_UNDEFINED otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    * @exception NumberFormatException if parse fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public static int parseUpperMap(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        int upperCase = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                int length = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (length >= 4 && length <=6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            upperCase = Integer.parseInt(s, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        else if (s.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            throw new NumberFormatException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return upperCase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    * Parse the lowercase mapping attribute for a Unicode character.  If there is a lowercase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    * mapping attribute and the parse succeeds, then the hasLowerMap field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    * the lowerMap field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    * If the lowercase mapping attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * hasLowerMap field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    * The lowercase mapping attribute should be a four to six digit hexadecimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    * @param s   the lowercase mapping attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    * @return   simple lowercase character mapping if defined, MAP_UNDEFINED otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    * @exception NumberFormatException if parse fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public static int parseLowerMap(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        int lowerCase = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                int length = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (length >= 4 && length <= 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            lowerCase = Integer.parseInt(s, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        else if (s.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            throw new NumberFormatException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return lowerCase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    * Parse the titlecase mapping attribute for a Unicode character.  If there is a titlecase
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    * mapping attribute and the parse succeeds, then the hasTitleMap field is set to true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    * the titleMap field of this UnicodeSpec object is updated, and false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    * If the titlecase mapping attribute is an empty string, the parse succeeds but the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    * hasTitleMap field is set to false. (and false is returned).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    * The titlecase mapping attribute should be a four to six digit hexadecimal integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    * @param s   the titlecase mapping attribute extracted from a line of the Unicode data file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    * @return   simple title case char mapping if defined, MAP_UNDEFINED otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    * @exception NumberFormatException if parse fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public static int parseTitleMap(String s) throws NumberFormatException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        int titleCase = MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                int length = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (length >= 4 && length <= 6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            titleCase = Integer.parseInt(s, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        else if (s.length() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new NumberFormatException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return titleCase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    * Read and parse a Unicode data file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    * @param file   a file specifying the Unicode data file to be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    * @return   an array of UnicodeSpec objects, one for each line of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    *           Unicode data file that could be successfully parsed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    *           specifying Unicode character attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    public static UnicodeSpec[] readSpecFile(File file, int plane) throws FileNotFoundException {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   394
        ArrayList<UnicodeSpec> list = new ArrayList<>(3000);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        UnicodeSpec[] result = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        int count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        BufferedReader f = new BufferedReader(new FileReader(file));
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   398
        String line = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        while(true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                line = f.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            catch (IOException e) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   405
                break loop;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   406
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            if (line == null) break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            UnicodeSpec item = parse(line.trim());
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   409
            int specPlane = item.getCodePoint() >>> 16;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   410
            if (specPlane < plane) continue;
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   411
            if (specPlane > plane) break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            if (item != null) {
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   414
                list.add(item);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
10110
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   417
        result = new UnicodeSpec[list.size()];
75674d930b1f 7058708: Eliminate JDK build tools build warnings
jjg
parents: 5506
diff changeset
   418
        list.toArray(result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    void setCodePoint(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        codePoint = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * Return the code point in this Unicode specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @return the char code point representing by the specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public int getCodePoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return codePoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    void setName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    void setGeneralCategory(byte category) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        generalCategory = category;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public byte getGeneralCategory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return generalCategory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    void setBidiCategory(byte category) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        bidiCategory = category;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public byte getBidiCategory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return bidiCategory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    void setCombiningClass(int combiningClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        this.combiningClass = combiningClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public int getCombiningClass() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        return combiningClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    void setDecomposition(String decomposition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        this.decomposition = decomposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public String getDecomposition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
         return decomposition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    void setDecimalValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        decimalValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    public int getDecimalValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return decimalValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public boolean isDecimalValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        return decimalValue != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    void setDigitValue(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        digitValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public int getDigitValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        return digitValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public boolean isDigitValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        return digitValue != -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    void setNumericValue(String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        numericValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public String getNumericValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        return numericValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public boolean isNumericValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return numericValue.length() > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    void setMirrored(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        mirrored = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public boolean isMirrored() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        return mirrored;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    void setOldName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        oldName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public String getOldName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        return oldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    void setComment(String comment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        this.comment = comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public String getComment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        return comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    void setUpperMap(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        upperMap = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public int getUpperMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return upperMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public boolean hasUpperMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return upperMap != MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    void setLowerMap(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        lowerMap = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public int getLowerMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return lowerMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public boolean hasLowerMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return lowerMap != MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    void setTitleMap(int ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        titleMap = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public int getTitleMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return titleMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public boolean hasTitleMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        return titleMap != MAP_UNDEFINED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    int codePoint;         // the characters UTF-32 code value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    String name;            // the ASCII name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    byte generalCategory;   // general category, available via Characte.getType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    byte bidiCategory;      // available via Character.getBidiType()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    int combiningClass;     // not used in Character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    String decomposition;   // not used in Character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    int decimalValue;       // decimal digit value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    int digitValue;         // not all digits are decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    String numericValue;    // numeric value if digit or non-digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    boolean mirrored;       //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    String oldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    String comment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    int upperMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    int lowerMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    int titleMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    // this is the number of fields in one line of the UnicodeData.txt file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    // each field is separated by a semicolon (a token)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    static final int REQUIRED_FIELDS = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * General category types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * To preserve compatibility, these values cannot be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    public static final byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        UNASSIGNED                  =  0, // Cn normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        UPPERCASE_LETTER            =  1, // Lu normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        LOWERCASE_LETTER            =  2, // Ll normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        TITLECASE_LETTER            =  3, // Lt normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        MODIFIER_LETTER             =  4, // Lm normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        OTHER_LETTER                =  5, // Lo normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        NON_SPACING_MARK            =  6, // Mn informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        ENCLOSING_MARK              =  7, // Me informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        COMBINING_SPACING_MARK      =  8, // Mc normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        DECIMAL_DIGIT_NUMBER        =  9, // Nd normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        LETTER_NUMBER               = 10, // Nl normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        OTHER_NUMBER                = 11, // No normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        SPACE_SEPARATOR             = 12, // Zs normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        LINE_SEPARATOR              = 13, // Zl normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        PARAGRAPH_SEPARATOR         = 14, // Zp normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        CONTROL                     = 15, // Cc normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        FORMAT                      = 16, // Cf normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        // 17 is unused for no apparent reason,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        // but must preserve forward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        PRIVATE_USE                 = 18, // Co normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        SURROGATE                   = 19, // Cs normative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        DASH_PUNCTUATION            = 20, // Pd informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        START_PUNCTUATION           = 21, // Ps informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        END_PUNCTUATION             = 22, // Pe informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        CONNECTOR_PUNCTUATION       = 23, // Pc informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        OTHER_PUNCTUATION           = 24, // Po informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        MATH_SYMBOL                 = 25, // Sm informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        CURRENCY_SYMBOL             = 26, // Sc informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        MODIFIER_SYMBOL             = 27, // Sk informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        OTHER_SYMBOL                = 28, // So informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        INITIAL_QUOTE_PUNCTUATION   = 29, // Pi informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        FINAL_QUOTE_PUNCTUATION     = 30, // Pf informative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        // this value is only used in the character generation tool
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        // it can change to accommodate the addition of new categories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        GENERAL_CATEGORY_COUNT      = 31; // sentinel value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    static final byte SHORT = 0, LONG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    // general category type strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    // NOTE: The order of this category array is dependent on the assignment of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    // category constants above. We want to access this array using constants above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    // [][SHORT] is the SHORT name, [][LONG] is the LONG name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    static final String[][] generalCategoryList = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        {"Cn", "UNASSIGNED"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        {"Lu", "UPPERCASE_LETTER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        {"Ll", "LOWERCASE_LETTER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        {"Lt", "TITLECASE_LETTER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        {"Lm", "MODIFIER_LETTER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        {"Lo", "OTHER_LETTER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        {"Mn", "NON_SPACING_MARK"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        {"Me", "ENCLOSING_MARK"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        {"Mc", "COMBINING_SPACING_MARK"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        {"Nd", "DECIMAL_DIGIT_NUMBER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        {"Nl", "LETTER_NUMBER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        {"No", "OTHER_NUMBER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        {"Zs", "SPACE_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        {"Zl", "LINE_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        {"Zp", "PARAGRAPH_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        {"Cc", "CONTROL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        {"Cf", "FORMAT"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        {"xx", "unused"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        {"Co", "PRIVATE_USE"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        {"Cs", "SURROGATE"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        {"Pd", "DASH_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        {"Ps", "START_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        {"Pe", "END_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        {"Pc", "CONNECTOR_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        {"Po", "OTHER_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        {"Sm", "MATH_SYMBOL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        {"Sc", "CURRENCY_SYMBOL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        {"Sk", "MODIFIER_SYMBOL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        {"So", "OTHER_SYMBOL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        {"Pi", "INITIAL_QUOTE_PUNCTUATION"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        {"Pf", "FINAL_QUOTE_PUNCTUATION"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Bidirectional categories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public static final byte
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   675
        DIRECTIONALITY_UNDEFINED                  = -1,
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   676
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // Strong category
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        DIRECTIONALITY_LEFT_TO_RIGHT              =  0, // L
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        DIRECTIONALITY_RIGHT_TO_LEFT              =  1, // R
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC       =  2, // AL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        // Weak category
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        DIRECTIONALITY_EUROPEAN_NUMBER            =  3, // EN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR  =  4, // ES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR =  5, // ET
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        DIRECTIONALITY_ARABIC_NUMBER              =  6, // AN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        DIRECTIONALITY_COMMON_NUMBER_SEPARATOR    =  7, // CS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        DIRECTIONALITY_NONSPACING_MARK            =  8, // NSM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        DIRECTIONALITY_BOUNDARY_NEUTRAL           =  9, // BN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // Neutral category
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        DIRECTIONALITY_PARAGRAPH_SEPARATOR        = 10, // B
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        DIRECTIONALITY_SEGMENT_SEPARATOR          = 11, // S
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        DIRECTIONALITY_WHITESPACE                 = 12, // WS
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   693
        DIRECTIONALITY_OTHER_NEUTRALS             = 13, // ON
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   694
        // Explicit Formatting category
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING    = 14, // LRE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE     = 15, // LRO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING    = 16, // RLE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE     = 17, // RLO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        DIRECTIONALITY_POP_DIRECTIONAL_FORMAT     = 18, // PDF
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   700
        DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE      = 19, // LRI
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   701
        DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE      = 20, // RLI
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   702
        DIRECTIONALITY_FIRST_STRONG_ISOLATE       = 21, // FSI
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   703
        DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE    = 22, // PDI
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   705
        DIRECTIONALITY_CATEGORY_COUNT             = 23; // sentinel value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    // If changes are made to the above bidi category assignments, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    // list of bidi category names must be changed to keep their order in synch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    // Access this list using the bidi category constants above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    static final String[][] bidiCategoryList = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        {"L", "DIRECTIONALITY_LEFT_TO_RIGHT"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        {"R", "DIRECTIONALITY_RIGHT_TO_LEFT"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        {"AL", "DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        {"EN", "DIRECTIONALITY_EUROPEAN_NUMBER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        {"ES", "DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        {"ET", "DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        {"AN", "DIRECTIONALITY_ARABIC_NUMBER"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
        {"CS", "DIRECTIONALITY_COMMON_NUMBER_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        {"NSM", "DIRECTIONALITY_NONSPACING_MARK"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        {"BN", "DIRECTIONALITY_BOUNDARY_NEUTRAL"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        {"B", "DIRECTIONALITY_PARAGRAPH_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        {"S", "DIRECTIONALITY_SEGMENT_SEPARATOR"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        {"WS", "DIRECTIONALITY_WHITESPACE"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        {"ON", "DIRECTIONALITY_OTHER_NEUTRALS"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        {"LRE", "DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        {"LRO", "DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        {"RLE", "DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        {"RLO", "DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        {"PDF", "DIRECTIONALITY_POP_DIRECTIONAL_FORMAT"},
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   730
        {"LRI", "DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE"},
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   731
        {"RLI", "DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE"},
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   732
        {"FSI", "DIRECTIONALITY_FIRST_STRONG_ISOLATE"},
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 23010
diff changeset
   733
        {"PDI", "DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE"},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    // Unicode specification lines have fields in this order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    static final byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        FIELD_VALUE         = 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        FIELD_NAME          = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        FIELD_CATEGORY      = 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        FIELD_CLASS         = 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        FIELD_BIDI          = 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        FIELD_DECOMPOSITION = 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        FIELD_DECIMAL       = 6,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        FIELD_DIGIT         = 7,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        FIELD_NUMERIC       = 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        FIELD_MIRRORED      = 9,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        FIELD_OLDNAME       = 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        FIELD_COMMENT       = 11,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        FIELD_UPPERCASE     = 12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        FIELD_LOWERCASE     = 13,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        FIELD_TITLECASE     = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        static final Pattern tokenSeparator = Pattern.compile(";");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                UnicodeSpec[] spec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                if (args.length == 2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                File file = new File(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                int plane = Integer.parseInt(args[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                spec = UnicodeSpec.readSpecFile(file, plane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                System.out.println("UnicodeSpec[" + spec.length + "]:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                for (int x=0; x<spec.length; x++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                        System.out.println(spec[x].toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                        catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
}