3261N/A * Copyright (c) 1996, 2010, 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 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/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. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/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-1998 - 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. 0N/A * The <code>CollationElementIterator</code> class is used as an iterator 0N/A * to walk through each character of an international string. Use the iterator 0N/A * to return the ordering priority of the positioned character. The ordering 0N/A * priority of a character, which we refer to as a key, defines how a character 0N/A * is collated in the given collation object. 0N/A * For example, consider the following in Spanish: 0N/A * "ca" -> the first key is key('c') and second key is key('a'). 0N/A * "cha" -> the first key is key('ch') and second key is key('a'). 0N/A * "\u00e4b"-> the first key is key('a'), the second key is key('e'), and 0N/A * the third key is key('b'). 0N/A * The key of a character is an integer composed of primary order(short), 0N/A * secondary order(byte), and tertiary order(byte). Java strictly defines 0N/A * the size and signedness of its primitive data types. Therefore, the static 0N/A * functions <code>primaryOrder</code>, <code>secondaryOrder</code>, and 0N/A * <code>tertiaryOrder</code> return <code>int</code>, <code>short</code>, 0N/A * and <code>short</code> respectively to ensure the correctness of the key 0N/A * Example of the iterator usage, 0N/A * String testString = "This is a test"; 3194N/A * Collator col = Collator.getInstance(); 3194N/A * if (col instanceof RuleBasedCollator) { 3194N/A * RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)col; 3194N/A * CollationElementIterator collationElementIterator = ruleBasedCollator.getCollationElementIterator(testString); 3194N/A * int primaryOrder = CollationElementIterator.primaryOrder(collationElementIterator.next()); 0N/A * <code>CollationElementIterator.next</code> returns the collation order 0N/A * of the next character. A collation order consists of primary order, 0N/A * secondary order and tertiary order. The data type of the collation 0N/A * order is <strong>int</strong>. The first 16 bits of a collation order 0N/A * is its primary order; the next 8 bits is the secondary order and the 0N/A * last 8 bits is the tertiary order. 3194N/A * <p><b>Note:</b> <code>CollationElementIterator</code> is a part of 3194N/A * <code>RuleBasedCollator</code> implementation. It is only usable 3194N/A * with <code>RuleBasedCollator</code> instances. 0N/A * @see RuleBasedCollator 0N/A * @author Helena Shih, Laura Werner, Richard Gillam 0N/A * Null order which indicates the end of string is reached by the 0N/A * CollationElementIterator constructor. This takes the source string and 0N/A * the collation object. The cursor will walk thru the source string based 0N/A * on the predefined collation rules. If the source string is empty, 0N/A * NULLORDER will be returned on the calls to next(). 0N/A * @param sourceText the source string. 0N/A * @param order the collation object. 0N/A * CollationElementIterator constructor. This takes the source string and 0N/A * the collation object. The cursor will walk thru the source string based 0N/A * on the predefined collation rules. If the source string is empty, 0N/A * NULLORDER will be returned on the calls to next(). 0N/A * @param sourceText the source string. 0N/A * @param order the collation object. 0N/A * Resets the cursor to the beginning of the string. The next call 0N/A * to next() will return the first collation element in the string. 0N/A * Get the next collation element in the string. <p>This iterator iterates 0N/A * over a sequence of collation elements that were built from the string. 0N/A * Because there isn't necessarily a one-to-one mapping from characters to 0N/A * collation elements, this doesn't mean the same thing as "return the 0N/A * collation element [or ordering priority] of the next character in the 0N/A * <p>This function returns the collation element that the iterator is currently 0N/A * pointing to and then updates the internal pointer to point to the next element. 0N/A * previous() updates the pointer first and then returns the element. This 0N/A * means that when you change direction while iterating (i.e., call next() and 0N/A * then call previous(), or call previous() and then call next()), you'll get 0N/A * back the same element twice.</p> 0N/A // convert the owner's mode to something the Normalizer understands 0N/A // if buffer contains any decomposed char values 0N/A // return their strength orders before continuing in 0N/A // the Normalizer's CharacterIterator. 0N/A // are we at the end of Normalizer's text? 0N/A * Get the previous collation element in the string. <p>This iterator iterates 0N/A * over a sequence of collation elements that were built from the string. 0N/A * Because there isn't necessarily a one-to-one mapping from characters to 0N/A * collation elements, this doesn't mean the same thing as "return the 0N/A * collation element [or ordering priority] of the previous character in the 0N/A * <p>This function updates the iterator's internal pointer to point to the 0N/A * collation element preceding the one it's currently pointing to and then 0N/A * returns that element, while next() returns the current element and then 0N/A * updates the pointer. This means that when you change direction while 0N/A * iterating (i.e., call next() and then call previous(), or call previous() 0N/A * and then call next()), you'll get back the same element twice.</p> 0N/A // convert the owner's mode to something the Normalizer understands 0N/A * Return the primary component of a collation element. 0N/A * @param order the collation element 0N/A * @return the element's primary component 0N/A * Return the secondary component of a collation element. 0N/A * @param order the collation element 0N/A * @return the element's secondary component 0N/A * Return the tertiary component of a collation element. 0N/A * @param order the collation element 0N/A * @return the element's tertiary component 0N/A * Get the comparison order in the desired strength. Ignore the other 0N/A * @param order The order value 0N/A * Sets the iterator to point to the collation element corresponding to 0N/A * the specified character (the parameter is a CHARACTER offset in the 0N/A * original string, not an offset into its corresponding sequence of 0N/A * collation elements). The value returned by the next call to next() 0N/A * will be the collation element corresponding to the specified position 0N/A * in the text. If that position is in the middle of a contracting 0N/A * character sequence, the result of the next call to next() is the 0N/A * collation element for that sequence. This means that getOffset() 0N/A * is not guaranteed to return the same value as was passed to a preceding 0N/A * call to setOffset(). 0N/A * @param newOffset The new character offset into the original text. 0N/A // if the desired character isn't used in a contracting character 0N/A // sequence, bypass all the backing-up logic-- we're sitting on 0N/A // the right character already 0N/A // walk backwards through the string until we see a character 0N/A // that DOESN'T participate in a contracting character sequence 0N/A // now walk forward using this object's next() method until 0N/A // we pass the starting point and set our current position 0N/A // to the beginning of the last "character" before or at 0N/A // our starting position 0N/A // we don't need this, since last is the last index 0N/A // that is the starting of the contraction which encompass 0N/A * Returns the character offset in the original text corresponding to the next 0N/A * collation element. (That is, getOffset() returns the position in the text 0N/A * corresponding to the collation element that will be returned by the next 0N/A * call to next().) This value will always be the index of the FIRST character 0N/A * corresponding to the collation element (a contracting character sequence is 0N/A * when two or more characters all correspond to the same collation element). 0N/A * This means if you do setOffset(x) followed immediately by getOffset(), getOffset() 0N/A * won't necessarily return x. 0N/A * @return The character offset in the original text corresponding to the collation 0N/A * element that will be returned by the next call to next(). 0N/A * Return the maximum length of any expansion sequences that end 0N/A * with the specified comparison order. 0N/A * @param order a collation order returned by previous or next. 0N/A * @return the maximum length of any expansion sequences ending 0N/A * with the specified order. 0N/A * Set a new string over which to iterate. 0N/A * @param source the new source text 0N/A * Set a new string over which to iterate. 0N/A * @param source the new source text. 0N/A //============================================================ 0N/A //============================================================ 0N/A * Determine if a character is a Thai vowel (which sorts after 0N/A * its base consonant). 0N/A return (
ch >=
0x0e40) && (
ch <=
0x0e44);
0N/A * Determine if a character is a Thai base consonant 0N/A return (
ch >=
0x0e01) && (
ch <=
0x0e2e);
0N/A * Determine if a character is a Lao vowel (which sorts after 0N/A * its base consonant). 0N/A return (
ch >=
0x0ec0) && (
ch <=
0x0ec4);
0N/A * Determine if a character is a Lao base consonant 0N/A return (
ch >=
0x0e81) && (
ch <=
0x0eae);
0N/A * This method produces a buffer which contains the collation 0N/A * elements for the two characters, with colFirst's values preceding 0N/A * another character's. Presumably, the other character precedes colFirst 0N/A * in logical order (otherwise you wouldn't need this method would you?). 0N/A * The assumption is that the other char's value(s) have already been 0N/A * computed. If this char has a single element it is passed to this 0N/A * method as lastValue, and lastExpansion is null. If it has an 0N/A * expansion it is passed in lastExpansion, and colLastValue is ignored. 0N/A * Check if a comparison order is ignorable. 0N/A * @return true if a character is ignorable, false otherwise. 0N/A * Get the ordering priority of the next contracting character in the 0N/A * @param ch the starting character of a contracting character token 0N/A * @return the next contracting character's ordering. Returns NULLORDER 0N/A * if the end of string is reached. 0N/A // First get the ordering of this single character, 0N/A // which is always the first element in the list 0N/A // find out the length of the longest contracting character sequence in the list. 0N/A // There's logic in the builder code to make sure the longest sequence is always 0N/A // (the Normalizer is cloned here so that the seeking we do in the next loop 0N/A // won't affect our real position in the text) 0N/A // extract the next maxLength characters in the string (we have to do this using the 0N/A // Normalizer to ensure that our offsets correspond to those the rest of the 0N/A // iterator is using) and store it in "fragment". 0N/A // now that we have that fragment, iterate through this list looking for the 0N/A // longest sequence that matches the characters in the actual text. (maxLength 0N/A // is used here to keep track of the length of the longest sequence) 0N/A // Upon exit from this loop, maxLength will contain the length of the matching 0N/A // sequence and order will contain the collation-element value corresponding 0N/A // seek our current iteration position to the end of the matching sequence 0N/A // and return the appropriate collation-element value (if there was no matching 0N/A // sequence, we're already seeked to the right position and order already contains 0N/A // the correct collation-element value for the single character) 0N/A * Get the ordering priority of the previous contracting character in the 0N/A * @param ch the starting character of a contracting character token 0N/A * @return the next contracting character's ordering. Returns NULLORDER 0N/A * if the end of string is reached. 0N/A // This function is identical to nextContractChar(), except that we've 0N/A // switched things so that the next() and previous() calls on the Normalizer 0N/A // are switched and so that we skip entry pairs with the fwd flag turned on 0N/A // rather than off. Notice that we still use append() and startsWith() when 0N/A // working on the fragment. This is because the entry pairs that are used 0N/A // in reverse iteration have their names reversed already.