File: UnicodeSpec.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (756 lines) | stat: -rw-r--r-- 27,757 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
/*
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
import java.util.regex.Pattern;
import java.util.ArrayList;

/**
 * The UnicodeSpec class provides a way to read in Unicode character
 * properties from a Unicode data file.  One instance of class UnicodeSpec
 * holds a decoded version of one line of the data file.  The file may
 * be obtained from www.unicode.org.  The method readSpecFile returns an array
 * of UnicodeSpec objects.
 *
 * @author      Guy Steele
 * @author  John O'Conner
 */

public class UnicodeSpec {

    public UnicodeSpec() {
        this(0xffff);
    }

    public UnicodeSpec(int codePoint) {
        this.codePoint = codePoint;
        generalCategory = UNASSIGNED;
        bidiCategory = DIRECTIONALITY_UNDEFINED;
        mirrored = false;
        titleMap = 0xFFFF;
        upperMap = 0xFFFF;
        lowerMap = 0xFFFF;
        decimalValue = -1;
        digitValue = -1;
        numericValue = "";
                oldName = null;
                comment = null;
                name = null;
    }

    public String toString() {
        StringBuffer result = new StringBuffer(hex6(codePoint));
        if (getUpperMap() != 0xffff) {
            result.append(", upper=").append(hex6(upperMap));
        }
        if (getLowerMap() != 0xffff) {
            result.append(", lower=").append(hex6(lowerMap));
        }
        if (getTitleMap() != 0xffff) {
            result.append(", title=").append(hex6(titleMap));
        }
        return result.toString();
    }

    static String hex4(int n) {
        String q = Long.toHexString(n & 0xFFFF).toUpperCase();
        return "0000".substring(Math.min(4, q.length())) + q;
    }

        static String hex6(int n) {
                String str = Integer.toHexString(n & 0xFFFFFF).toUpperCase();
                return "000000".substring(Math.min(6, str.length())) + str;

        }


    /**
    * Given one line of a Unicode data file as a String, parse the line
    * and return a UnicodeSpec object that contains the same character information.
    *
    * @param s a line of the Unicode data file to be parsed
    * @return a UnicodeSpec object, or null if the parsing process failed for some reason
    */
    public static UnicodeSpec parse(String s) {
        UnicodeSpec spec = null;
        String[] tokens = null;

        try {
                        tokens = tokenSeparator.split(s, REQUIRED_FIELDS);
            spec = new UnicodeSpec();
            spec.setCodePoint(parseCodePoint(tokens[FIELD_VALUE]));
            spec.setName(parseName(tokens[FIELD_NAME]));
            spec.setGeneralCategory(parseGeneralCategory(tokens[FIELD_CATEGORY]));
            spec.setBidiCategory(parseBidiCategory(tokens[FIELD_BIDI]));
            spec.setCombiningClass(parseCombiningClass(tokens[FIELD_CLASS]));
            spec.setDecomposition(parseDecomposition(tokens[FIELD_DECOMPOSITION]));
            spec.setDecimalValue(parseDecimalValue(tokens[FIELD_DECIMAL]));
            spec.setDigitValue(parseDigitValue(tokens[FIELD_DIGIT]));
            spec.setNumericValue(parseNumericValue(tokens[FIELD_NUMERIC]));
            spec.setMirrored(parseMirrored(tokens[FIELD_MIRRORED]));
            spec.setOldName(parseOldName(tokens[FIELD_OLDNAME]));
            spec.setComment(parseComment(tokens[FIELD_COMMENT]));
            spec.setUpperMap(parseUpperMap(tokens[FIELD_UPPERCASE]));
            spec.setLowerMap(parseLowerMap(tokens[FIELD_LOWERCASE]));
            spec.setTitleMap(parseTitleMap(tokens[FIELD_TITLECASE]));
        }
        catch(Exception e) {
            spec = null;
            System.out.println("Error parsing spec line.");
        }
        return spec;
    }

    /**
    * Parse the codePoint attribute for a Unicode character.  If the parse succeeds,
    * the codePoint field of this UnicodeSpec object is updated and false is returned.
    *
    * The codePoint attribute should be a four-digit hexadecimal integer.
    *
    * @param s   the codePoint attribute extracted from a line of the Unicode data file
    * @return   code point if successful
    * @exception NumberFormatException if unable to parse argument
    */
    public static int parseCodePoint(String s) throws NumberFormatException {
        return Integer.parseInt(s, 16);
    }

    public static String parseName(String s) throws Exception {
        if (s==null) throw new Exception("Cannot parse name.");
        return s;
    }

    public static byte parseGeneralCategory(String s) throws Exception {
        byte category = GENERAL_CATEGORY_COUNT;

        for (byte x=0; x<generalCategoryList.length; x++) {
            if (s.equals(generalCategoryList[x][SHORT])) {
                category = x;
                break;
            }
        }
        if (category >= GENERAL_CATEGORY_COUNT) {
            throw new Exception("Could not parse general category.");
        }
        return category;
    }

    public static byte parseBidiCategory(String s) throws Exception {
        byte category = DIRECTIONALITY_CATEGORY_COUNT;

        for (byte x=0; x<bidiCategoryList.length; x++) {
            if (s.equals(bidiCategoryList[x][SHORT])) {
                category = x;
                break;
            }
        }
        if (category >= DIRECTIONALITY_CATEGORY_COUNT) {
            throw new Exception("Could not parse bidi category.");
        }
        return category;
    }


    /**
    * Parse the combining attribute for a Unicode character.  If there is a combining
    * attribute and the parse succeeds, then the hasCombining field is set to true,
    * the combining field of this UnicodeSpec object is updated, and false is returned.
    * If the combining attribute is an empty string, the parse succeeds but the
    * hasCombining field is set to false. (and false is returned).
    *
    * The combining attribute, if any, should be a nonnegative decimal integer.
    *
    * @param s   the combining attribute extracted from a line of the Unicode data file
    * @return   the combining class value if any, -1 if property not defined
    * @exception Exception if can't parse the combining class
    */

    public static int parseCombiningClass(String s) throws Exception {
        int combining = -1;
        if (s.length()>0) {
            combining = Integer.parseInt(s, 10);
        }
        return combining;
    }

    /**
    * Parse the decomposition attribute for a Unicode character.  If the parse succeeds,
    * the decomposition field of this UnicodeSpec object is updated and false is returned.
    *
    * The decomposition attribute is complicated; for now, it is treated as a string.
    *
    * @param s   the decomposition attribute extracted from a line of the Unicode data file
    * @return   true if the parse failed; otherwise false
    */

    public static String parseDecomposition(String s) throws Exception {
        if (s==null) throw new Exception("Cannot parse decomposition.");
        return s;
    }


    /**
    * Parse the decimal value attribute for a Unicode character.  If there is a decimal value
    * attribute and the parse succeeds, then the hasDecimalValue field is set to true,
    * the decimalValue field of this UnicodeSpec object is updated, and false is returned.
    * If the decimal value attribute is an empty string, the parse succeeds but the
    * hasDecimalValue field is set to false. (and false is returned).
    *
    * The decimal value attribute, if any, should be a nonnegative decimal integer.
    *
    * @param s   the decimal value attribute extracted from a line of the Unicode data file
    * @return   the decimal value as an int, -1 if no decimal value defined
    * @exception NumberFormatException if the parse fails
    */
    public static int parseDecimalValue(String s) throws NumberFormatException {
        int value = -1;

        if (s.length() > 0) {
            value = Integer.parseInt(s, 10);
        }
        return value;
    }

    /**
    * Parse the digit value attribute for a Unicode character.  If there is a digit value
    * attribute and the parse succeeds, then the hasDigitValue field is set to true,
    * the digitValue field of this UnicodeSpec object is updated, and false is returned.
    * If the digit value attribute is an empty string, the parse succeeds but the
    * hasDigitValue field is set to false. (and false is returned).
    *
    * The digit value attribute, if any, should be a nonnegative decimal integer.
    *
    * @param s   the digit value attribute extracted from a line of the Unicode data file
    * @return   the digit value as an non-negative int, or -1 if no digit property defined
    * @exception NumberFormatException if the parse fails
    */
    public static int parseDigitValue(String s) throws NumberFormatException {
        int value = -1;

        if (s.length() > 0) {
            value = Integer.parseInt(s, 10);
        }
        return value;
    }

    public static String parseNumericValue(String s) throws Exception {
        if (s == null) throw new Exception("Cannot parse numeric value.");
        return s;
    }

    public static String parseComment(String s) throws Exception {
        if (s == null) throw new Exception("Cannot parse comment.");
        return s;
    }

    public static boolean parseMirrored(String s) throws Exception {
        boolean mirrored;
        if (s.length() == 1) {
            if (s.charAt(0) == 'Y') {mirrored = true;}
            else if (s.charAt(0) == 'N') {mirrored = false;}
            else {throw new Exception("Cannot parse mirrored property.");}
        }
        else { throw new Exception("Cannot parse mirrored property.");}
        return mirrored;
    }

    public static String parseOldName(String s) throws Exception {
        if (s == null) throw new Exception("Cannot parse old name");
        return s;
    }

    /**
    * Parse the uppercase mapping attribute for a Unicode character.  If there is a uppercase
    * mapping attribute and the parse succeeds, then the hasUpperMap field is set to true,
    * the upperMap field of this UnicodeSpec object is updated, and false is returned.
    * If the uppercase mapping attribute is an empty string, the parse succeeds but the
    * hasUpperMap field is set to false. (and false is returned).
    *
    * The uppercase mapping attribute should be a four-digit hexadecimal integer.
    *
    * @param s   the uppercase mapping attribute extracted from a line of the Unicode data file
    * @return   uppercase char if defined, \uffff otherwise
    * @exception NumberFormatException if parse fails
    */
    public static int parseUpperMap(String s) throws NumberFormatException {
        int upperCase = 0xFFFF;

        if (s.length() >= 4) {
            upperCase = Integer.parseInt(s, 16);
        }
        else if (s.length() != 0) {
            throw new NumberFormatException();
        }
        return upperCase;
    }

    /**
    * Parse the lowercase mapping attribute for a Unicode character.  If there is a lowercase
    * mapping attribute and the parse succeeds, then the hasLowerMap field is set to true,
    * the lowerMap field of this UnicodeSpec object is updated, and false is returned.
    * If the lowercase mapping attribute is an empty string, the parse succeeds but the
     * hasLowerMap field is set to false. (and false is returned).
    *
    * The lowercase mapping attribute should be a four-digit hexadecimal integer.
    *
    * @param s   the lowercase mapping attribute extracted from a line of the Unicode data file
    * @return   lowercase char mapping if defined, \uFFFF otherwise
    * @exception NumberFormatException if parse fails
    */
    public static int parseLowerMap(String s) throws NumberFormatException {
        int lowerCase = 0xFFFF;

        if (s.length() >= 4) {
            lowerCase = Integer.parseInt(s, 16);
        }
        else if (s.length() != 0) {
            throw new NumberFormatException();
        }
        return lowerCase;
    }

    /**
    * Parse the titlecase mapping attribute for a Unicode character.  If there is a titlecase
    * mapping attribute and the parse succeeds, then the hasTitleMap field is set to true,
    * the titleMap field of this UnicodeSpec object is updated, and false is returned.
    * If the titlecase mapping attribute is an empty string, the parse succeeds but the
    * hasTitleMap field is set to false. (and false is returned).
    *
    * The titlecase mapping attribute should be a four-digit hexadecimal integer.
    *
    * @param s   the titlecase mapping attribute extracted from a line of the Unicode data file
    * @return   title case char mapping if defined, \uFFFF otherwise
    * @exception NumberFormatException if parse fails
    */
    public static int parseTitleMap(String s) throws NumberFormatException {
        int titleCase = 0xFFFF;

        if (s.length() >= 4) {
            titleCase = Integer.parseInt(s, 16);
        }
        else if (s.length() != 0) {
            throw new NumberFormatException();
        }
        return titleCase;
    }

    /**
    * Read and parse a Unicode data file.
    *
    * @param file   a file specifying the Unicode data file to be read
    * @return   an array of UnicodeSpec objects, one for each line of the
    *           Unicode data file that could be successfully parsed as
    *           specifying Unicode character attributes
    */

    public static UnicodeSpec[] readSpecFile(File file, int plane) throws FileNotFoundException {
                ArrayList<UnicodeSpec> list = new ArrayList<>(3000);
        UnicodeSpec[] result = null;
        int count = 0;
        BufferedReader f = new BufferedReader(new FileReader(file));
                String line = null;
        loop:
        while(true) {
            try {
                line = f.readLine();
            }
            catch (IOException e) {
                                break loop;
                        }
            if (line == null) break loop;
            UnicodeSpec item = parse(line.trim());
                        int specPlane = item.getCodePoint() >>> 16;
                        if (specPlane < plane) continue;
                        if (specPlane > plane) break;

            if (item != null) {
                                list.add(item);
            }
        }
                result = new UnicodeSpec[list.size()];
                list.toArray(result);
        return result;
    }

    void setCodePoint(int value) {
        codePoint = value;
    }

    /**
     * Return the code point in this Unicode specification
     * @return the char code point representing by the specification
     */
    public int getCodePoint() {
        return codePoint;
    }

    void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    void setGeneralCategory(byte category) {
        generalCategory = category;
    }

    public byte getGeneralCategory() {
        return generalCategory;
    }

    void setBidiCategory(byte category) {
        bidiCategory = category;
    }

    public byte getBidiCategory() {
        return bidiCategory;
    }

    void setCombiningClass(int combiningClass) {
        this.combiningClass = combiningClass;
    }

    public int getCombiningClass() {
        return combiningClass;
    }

    void setDecomposition(String decomposition) {
        this.decomposition = decomposition;
    }

    public String getDecomposition() {
         return decomposition;
    }

    void setDecimalValue(int value) {
        decimalValue = value;
    }

    public int getDecimalValue() {
        return decimalValue;
    }

    public boolean isDecimalValue() {
        return decimalValue != -1;
    }

    void setDigitValue(int value) {
        digitValue = value;
    }

    public int getDigitValue() {
        return digitValue;
    }

    public boolean isDigitValue() {
        return digitValue != -1;
    }

    void setNumericValue(String value) {
        numericValue = value;
    }

    public String getNumericValue() {
        return numericValue;
    }

    public boolean isNumericValue() {
        return numericValue.length() > 0;
    }

    void setMirrored(boolean value) {
        mirrored = value;
    }

    public boolean isMirrored() {
        return mirrored;
    }

    void setOldName(String name) {
        oldName = name;
    }

    public String getOldName() {
        return oldName;
    }

    void setComment(String comment) {
        this.comment = comment;
    }

    public String getComment() {
        return comment;
    }

    void setUpperMap(int ch) {
        upperMap = ch;
    };

    public int getUpperMap() {
        return upperMap;
    }

    public boolean hasUpperMap() {
        return upperMap != 0xffff;
    }

    void setLowerMap(int ch) {
        lowerMap = ch;
    }

    public int getLowerMap() {
        return lowerMap;
    }

    public boolean hasLowerMap() {
        return lowerMap != 0xffff;
    }

    void setTitleMap(int ch) {
        titleMap = ch;
    }

    public int getTitleMap() {
        return titleMap;
    }

    public boolean hasTitleMap() {
        return titleMap != 0xffff;
    }

    int codePoint;         // the characters UTF-32 code value
    String name;            // the ASCII name
    byte generalCategory;   // general category, available via Characte.getType()
    byte bidiCategory;      // available via Character.getBidiType()
    int combiningClass;     // not used in Character
    String decomposition;   // not used in Character
    int decimalValue;       // decimal digit value
    int digitValue;         // not all digits are decimal
    String numericValue;    // numeric value if digit or non-digit
    boolean mirrored;       //
    String oldName;
    String comment;
    int upperMap;
    int lowerMap;
    int titleMap;

    // this is the number of fields in one line of the UnicodeData.txt file
    // each field is separated by a semicolon (a token)
    static final int REQUIRED_FIELDS = 15;

    /**
     * General category types
     * To preserve compatibility, these values cannot be changed
     */
    public static final byte
        UNASSIGNED                  =  0, // Cn normative
        UPPERCASE_LETTER            =  1, // Lu normative
        LOWERCASE_LETTER            =  2, // Ll normative
        TITLECASE_LETTER            =  3, // Lt normative
        MODIFIER_LETTER             =  4, // Lm normative
        OTHER_LETTER                =  5, // Lo normative
        NON_SPACING_MARK            =  6, // Mn informative
        ENCLOSING_MARK              =  7, // Me informative
        COMBINING_SPACING_MARK      =  8, // Mc normative
        DECIMAL_DIGIT_NUMBER        =  9, // Nd normative
        LETTER_NUMBER               = 10, // Nl normative
        OTHER_NUMBER                = 11, // No normative
        SPACE_SEPARATOR             = 12, // Zs normative
        LINE_SEPARATOR              = 13, // Zl normative
        PARAGRAPH_SEPARATOR         = 14, // Zp normative
        CONTROL                     = 15, // Cc normative
        FORMAT                      = 16, // Cf normative
        // 17 is unused for no apparent reason,
        // but must preserve forward compatibility
        PRIVATE_USE                 = 18, // Co normative
        SURROGATE                   = 19, // Cs normative
        DASH_PUNCTUATION            = 20, // Pd informative
        START_PUNCTUATION           = 21, // Ps informative
        END_PUNCTUATION             = 22, // Pe informative
        CONNECTOR_PUNCTUATION       = 23, // Pc informative
        OTHER_PUNCTUATION           = 24, // Po informative
        MATH_SYMBOL                 = 25, // Sm informative
        CURRENCY_SYMBOL             = 26, // Sc informative
        MODIFIER_SYMBOL             = 27, // Sk informative
        OTHER_SYMBOL                = 28, // So informative
        INITIAL_QUOTE_PUNCTUATION   = 29, // Pi informative
        FINAL_QUOTE_PUNCTUATION     = 30, // Pf informative

        // this value is only used in the character generation tool
        // it can change to accommodate the addition of new categories.
        GENERAL_CATEGORY_COUNT      = 31; // sentinel value

    static final byte SHORT = 0, LONG = 1;
    // general category type strings
    // NOTE: The order of this category array is dependent on the assignment of
    // category constants above. We want to access this array using constants above.
    // [][SHORT] is the SHORT name, [][LONG] is the LONG name
    static final String[][] generalCategoryList = {
        {"Cn", "UNASSIGNED"},
        {"Lu", "UPPERCASE_LETTER"},
        {"Ll", "LOWERCASE_LETTER"},
        {"Lt", "TITLECASE_LETTER"},
        {"Lm", "MODIFIER_LETTER"},
        {"Lo", "OTHER_LETTER"},
        {"Mn", "NON_SPACING_MARK"},
        {"Me", "ENCLOSING_MARK"},
        {"Mc", "COMBINING_SPACING_MARK"},
        {"Nd", "DECIMAL_DIGIT_NUMBER"},
        {"Nl", "LETTER_NUMBER"},
        {"No", "OTHER_NUMBER"},
        {"Zs", "SPACE_SEPARATOR"},
        {"Zl", "LINE_SEPARATOR"},
        {"Zp", "PARAGRAPH_SEPARATOR"},
        {"Cc", "CONTROL"},
        {"Cf", "FORMAT"},
        {"xx", "unused"},
        {"Co", "PRIVATE_USE"},
        {"Cs", "SURROGATE"},
        {"Pd", "DASH_PUNCTUATION"},
        {"Ps", "START_PUNCTUATION"},
        {"Pe", "END_PUNCTUATION"},
        {"Pc", "CONNECTOR_PUNCTUATION"},
        {"Po", "OTHER_PUNCTUATION"},
        {"Sm", "MATH_SYMBOL"},
        {"Sc", "CURRENCY_SYMBOL"},
        {"Sk", "MODIFIER_SYMBOL"},
        {"So", "OTHER_SYMBOL"},
        {"Pi", "INITIAL_QUOTE_PUNCTUATION"},
        {"Pf", "FINAL_QUOTE_PUNCTUATION"}
    };

    /**
     * Bidirectional categories
     */
    public static final byte
                DIRECTIONALITY_UNDEFINED                  = -1,
        // Strong category
        DIRECTIONALITY_LEFT_TO_RIGHT              =  0, // L
        DIRECTIONALITY_RIGHT_TO_LEFT              =  1, // R
        DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC       =  2, // AL
        // Weak category
        DIRECTIONALITY_EUROPEAN_NUMBER            =  3, // EN
        DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR  =  4, // ES
        DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR =  5, // ET
        DIRECTIONALITY_ARABIC_NUMBER              =  6, // AN
        DIRECTIONALITY_COMMON_NUMBER_SEPARATOR    =  7, // CS
        DIRECTIONALITY_NONSPACING_MARK            =  8, // NSM
        DIRECTIONALITY_BOUNDARY_NEUTRAL           =  9, // BN
        // Neutral category
        DIRECTIONALITY_PARAGRAPH_SEPARATOR        = 10, // B
        DIRECTIONALITY_SEGMENT_SEPARATOR          = 11, // S
        DIRECTIONALITY_WHITESPACE                 = 12, // WS
        DIRECTIONALITY_OTHER_NEUTRALS              = 13, // ON

        DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING    = 14, // LRE
        DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE     = 15, // LRO
        DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING    = 16, // RLE
        DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE     = 17, // RLO
        DIRECTIONALITY_POP_DIRECTIONAL_FORMAT     = 18, // PDF

        DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE      = 19, // LRI
        DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE      = 20, // RLI
        DIRECTIONALITY_FIRST_STRONG_ISOLATE       = 21, // FSI
        DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE    = 22, // PDI

        DIRECTIONALITY_CATEGORY_COUNT             = 23; // sentinel value

    // If changes are made to the above bidi category assignments, this
    // list of bidi category names must be changed to keep their order in synch.
    // Access this list using the bidi category constants above.
    static final String[][] bidiCategoryList = {
        {"L", "DIRECTIONALITY_LEFT_TO_RIGHT"},
        {"R", "DIRECTIONALITY_RIGHT_TO_LEFT"},
        {"AL", "DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC"},
        {"EN", "DIRECTIONALITY_EUROPEAN_NUMBER"},
        {"ES", "DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR"},
        {"ET", "DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR"},
        {"AN", "DIRECTIONALITY_ARABIC_NUMBER"},
        {"CS", "DIRECTIONALITY_COMMON_NUMBER_SEPARATOR"},
        {"NSM", "DIRECTIONALITY_NONSPACING_MARK"},
        {"BN", "DIRECTIONALITY_BOUNDARY_NEUTRAL"},
        {"B", "DIRECTIONALITY_PARAGRAPH_SEPARATOR"},
        {"S", "DIRECTIONALITY_SEGMENT_SEPARATOR"},
        {"WS", "DIRECTIONALITY_WHITESPACE"},
        {"ON", "DIRECTIONALITY_OTHER_NEUTRALS"},
        {"LRE", "DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING"},
        {"LRO", "DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE"},
        {"RLE", "DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING"},
        {"RLO", "DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE"},
        {"PDF", "DIRECTIONALITY_POP_DIRECTIONAL_FORMAT"},
        {"LRI", "DIRECTIONALITY_LEFT_TO_RIGHT_ISOLATE"},
        {"RLI", "DIRECTIONALITY_RIGHT_TO_LEFT_ISOLATE"},
        {"FSI", "DIRECTIONALITY_FIRST_STRONG_ISOLATE"},
        {"PDI", "DIRECTIONALITY_POP_DIRECTIONAL_ISOLATE"},

    };

    // Unicode specification lines have fields in this order.
    static final byte
        FIELD_VALUE         = 0,
        FIELD_NAME          = 1,
        FIELD_CATEGORY      = 2,
        FIELD_CLASS         = 3,
        FIELD_BIDI          = 4,
        FIELD_DECOMPOSITION = 5,
        FIELD_DECIMAL       = 6,
        FIELD_DIGIT         = 7,
        FIELD_NUMERIC       = 8,
        FIELD_MIRRORED      = 9,
        FIELD_OLDNAME       = 10,
        FIELD_COMMENT       = 11,
        FIELD_UPPERCASE     = 12,
        FIELD_LOWERCASE     = 13,
        FIELD_TITLECASE     = 14;

        static final Pattern tokenSeparator = Pattern.compile(";");

        public static void main(String[] args) {
                UnicodeSpec[] spec = null;
                if (args.length == 2 ) {
                        try {
                                File file = new File(args[0]);
                                int plane = Integer.parseInt(args[1]);
                                spec = UnicodeSpec.readSpecFile(file, plane);
                                System.out.println("UnicodeSpec[" + spec.length + "]:");
                                for (int x=0; x<spec.length; x++) {
                                        System.out.println(spec[x].toString());
                                }
                        }
                        catch(Exception e) {
                                e.printStackTrace();
                        }
                }

        }

}