MergeCollation.java revision 2362
0N/A * Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A * or visit www.oracle.com if you need additional information or have any 0N/A * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved 0N/A * The original version of this source code and documentation is copyrighted 0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These 0N/A * materials are provided under terms of a License Agreement between Taligent 0N/A * and Sun. This technology is protected by multiple US and International 0N/A * patents. This notice and attribution to Taligent may not be removed. 0N/A * Taligent is a registered trademark of Taligent, Inc. * Utility class for normalizing and merging patterns for collation. * Patterns are strings of the form <entry>*, where <entry> has the * <entry> := <separator><chars>{"/"<extension>} * <separator> := "=", ",", ";", "<", "&" * <chars>, and <extension> are both arbitrary strings. * unquoted whitespaces are ignored. * 'xxx' can be used to quote characters * One difference from Collator is that & is used to reset to a current * point. Or, in other words, it introduces a new sequence which is to * That is: "a < b < c < d" is the same as "a < b & b < c & c < d" OR * XXX: make '' be a single quote. * @author Mark Davis, Helena Shih * @exception ParseException If the input pattern is incorrect. * recovers current pattern * recovers current pattern. * @param withWhiteSpace puts spacing around the entries, and \n * emits the pattern for collation builder. * @return emits the string in the format understable to the collation * emits the pattern for collation builder. * @param withWhiteSpace puts spacing around the entries, and \n * @return emits the string in the format understable to the collation * adds a pattern to the current one. * @param pattern the new pattern to be added * gets count of separate entries * @return the size of pattern entries * gets count of separate entries * @param index the offset of the desired pattern entry * @return the requested pattern entry //============================================================ //============================================================ // This is really used as a local variable inside fixEntry, but we cache // it here to avoid newing it up every time the method is called. // When building a MergeCollation, we need to do lots of searches to see // whether a given entry is already in the table. Since we're using an // array, this would make the algorithm O(N*N). To speed things up, we // use this bit array to remember whether the array contains any entries // starting with each Unicode character. If not, we can avoid the search. // Using BitSet would make this easier, but it's significantly slower. If the strength is RESET, then just change the lastEntry to be the current. (If the current is not in patterns, signal an error). If not, then remove the current entry, and add it after lastEntry (which is usually at the end). // check to see whether the new entry has the same characters as the previous // entry did (this can happen when a pattern declaring a difference between two // strings that are canonically equivalent is normalized). If so, and the strength // is anything other than IDENTICAL or RESET, throw an exception (you can't // declare a string to be unequal to itself). --rtg 5/24/99 +
newEntry +
" are adjacent in the rules, but have conflicting " +
"strengths: A character can't be unequal to itself.", -
1);
// otherwise, just skip this entry and behave as though you never saw it // We're going to add an element that starts with this // character, so go ahead and set its bit. // Search backwards for string that contains this one; // most likely entry is last one