1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
55 * that will go into the tables object itself. This object communicates
56 * with RBCollationTables through a separate class, RBCollationTables.BuildAPI,
57 * this is an inner class of RBCollationTables and provides a separate
58 * private API for communication with RBTableBuilder.
59 * This class isn't just an inner class of RBCollationTables itself because
60 * of its large size. For source-code readability, it seemed better for the
61 * builder to have its own source file.
62 */
63 final class RBTableBuilder {
64
65 public RBTableBuilder(RBCollationTables.BuildAPI tables) {
66 this.tables = tables;
67 }
68
69 /**
70 * Create a table-based collation object with the given rules.
71 * This is the main function that actually builds the tables and
72 * stores them back in the RBCollationTables object. It is called
73 * ONLY by the RBCollationTables constructor.
74 * @see RuleBasedCollator#RuleBasedCollator
75 * @exception ParseException If the rules format is incorrect.
76 */
77
78 public void build(String pattern, int decmp) throws ParseException {
79 String expChars;
80 String groupChars;
81 if (pattern.isEmpty())
82 throw new ParseException("Build rules empty.", 0);
83
84 // This array maps Unicode characters to their collation ordering
85 mapping = new UCompactIntArray(RBCollationTables.UNMAPPED);
86 // Normalize the build rules. Find occurances of all decomposed characters
87 // and normalize the rules before feeding into the builder. By "normalize",
88 // we mean that all precomposed Unicode characters must be converted into
89 // a base character and one or more combining characters (such as accents).
90 // When there are multiple combining characters attached to a base character,
91 // the combining characters must be in their canonical order
92 //
93 // sherman/Note:
94 //(1)decmp will be NO_DECOMPOSITION only in ko locale to prevent decompose
95 //hangual syllables to jamos, so we can actually just call decompose with
|
1 /*
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
55 * that will go into the tables object itself. This object communicates
56 * with RBCollationTables through a separate class, RBCollationTables.BuildAPI,
57 * this is an inner class of RBCollationTables and provides a separate
58 * private API for communication with RBTableBuilder.
59 * This class isn't just an inner class of RBCollationTables itself because
60 * of its large size. For source-code readability, it seemed better for the
61 * builder to have its own source file.
62 */
63 final class RBTableBuilder {
64
65 public RBTableBuilder(RBCollationTables.BuildAPI tables) {
66 this.tables = tables;
67 }
68
69 /**
70 * Create a table-based collation object with the given rules.
71 * This is the main function that actually builds the tables and
72 * stores them back in the RBCollationTables object. It is called
73 * ONLY by the RBCollationTables constructor.
74 * @see RuleBasedCollator#RuleBasedCollator
75 * @throws ParseException If the rules format is incorrect.
76 */
77
78 public void build(String pattern, int decmp) throws ParseException {
79 String expChars;
80 String groupChars;
81 if (pattern.isEmpty())
82 throw new ParseException("Build rules empty.", 0);
83
84 // This array maps Unicode characters to their collation ordering
85 mapping = new UCompactIntArray(RBCollationTables.UNMAPPED);
86 // Normalize the build rules. Find occurances of all decomposed characters
87 // and normalize the rules before feeding into the builder. By "normalize",
88 // we mean that all precomposed Unicode characters must be converted into
89 // a base character and one or more combining characters (such as accents).
90 // When there are multiple combining characters attached to a base character,
91 // the combining characters must be in their canonical order
92 //
93 // sherman/Note:
94 //(1)decmp will be NO_DECOMPOSITION only in ko locale to prevent decompose
95 //hangual syllables to jamos, so we can actually just call decompose with
|