jdk/src/java.base/share/classes/java/text/CollationElementIterator.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 25859 3317bb8137f4
child 45434 4582657c7260
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
     2
 * Copyright (c) 1996, 2013, 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: 4839
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: 4839
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: 4839
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4839
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4839
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996-1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.Character;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import sun.text.CollatorUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import sun.text.normalizer.NormalizerBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The <code>CollationElementIterator</code> class is used as an iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * to walk through each character of an international string. Use the iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * to return the ordering priority of the positioned character. The ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * priority of a character, which we refer to as a key, defines how a character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * is collated in the given collation object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * For example, consider the following in Spanish:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <pre>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    57
 * "ca" &rarr; the first key is key('c') and second key is key('a').
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    58
 * "cha" &rarr; the first key is key('ch') and second key is key('a').
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * And in German,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <pre>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
    64
 * "\u00e4b" &rarr; the first key is key('a'), the second key is key('e'), and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the third key is key('b').
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * The key of a character is an integer composed of primary order(short),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * secondary order(byte), and tertiary order(byte). Java strictly defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * the size and signedness of its primitive data types. Therefore, the static
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * functions <code>primaryOrder</code>, <code>secondaryOrder</code>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>tertiaryOrder</code> return <code>int</code>, <code>short</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * and <code>short</code> respectively to ensure the correctness of the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * Example of the iterator usage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *  String testString = "This is a test";
7509
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    82
 *  Collator col = Collator.getInstance();
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    83
 *  if (col instanceof RuleBasedCollator) {
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    84
 *      RuleBasedCollator ruleBasedCollator = (RuleBasedCollator)col;
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    85
 *      CollationElementIterator collationElementIterator = ruleBasedCollator.getCollationElementIterator(testString);
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    86
 *      int primaryOrder = CollationElementIterator.primaryOrder(collationElementIterator.next());
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    87
 *          :
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
    88
 *  }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <code>CollationElementIterator.next</code> returns the collation order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * of the next character. A collation order consists of primary order,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * secondary order and tertiary order. The data type of the collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * order is <strong>int</strong>. The first 16 bits of a collation order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * is its primary order; the next 8 bits is the secondary order and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * last 8 bits is the tertiary order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *
7509
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
   100
 * <p><b>Note:</b> <code>CollationElementIterator</code> is a part of
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
   101
 * <code>RuleBasedCollator</code> implementation. It is only usable
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
   102
 * with <code>RuleBasedCollator</code> instances.
bc7eaae38fff 6486695: [Col] Doc: CollationElementIterator example assumes Collator.getInstance return type
naoto
parents: 5506
diff changeset
   103
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @see                Collator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @see                RuleBasedCollator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * @author             Helena Shih, Laura Werner, Richard Gillam
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
public final class CollationElementIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Null order which indicates the end of string is reached by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * cursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   114
    public static final int NULLORDER = 0xffffffff;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * CollationElementIterator constructor.  This takes the source string and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the collation object.  The cursor will walk thru the source string based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * on the predefined collation rules.  If the source string is empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * NULLORDER will be returned on the calls to next().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param sourceText the source string.
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 12848
diff changeset
   122
     * @param owner the collation object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    CollationElementIterator(String sourceText, RuleBasedCollator owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.owner = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        ordering = owner.getTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if ( sourceText.length() != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            NormalizerBase.Mode mode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            text = new NormalizerBase(sourceText, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * CollationElementIterator constructor.  This takes the source string and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * the collation object.  The cursor will walk thru the source string based
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * on the predefined collation rules.  If the source string is empty,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * NULLORDER will be returned on the calls to next().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param sourceText the source string.
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 12848
diff changeset
   140
     * @param owner the collation object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    CollationElementIterator(CharacterIterator sourceText, RuleBasedCollator owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.owner = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        ordering = owner.getTables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        NormalizerBase.Mode mode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        text = new NormalizerBase(sourceText, mode);
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
     * Resets the cursor to the beginning of the string.  The next call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * to next() will return the first collation element in the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void reset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            text.reset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            NormalizerBase.Mode mode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            text.setMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Get the next collation element in the string.  <p>This iterator iterates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * over a sequence of collation elements that were built from the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Because there isn't necessarily a one-to-one mapping from characters to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * collation elements, this doesn't mean the same thing as "return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * collation element [or ordering priority] of the next character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * string".</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p>This function returns the collation element that the iterator is currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * pointing to and then updates the internal pointer to point to the next element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * previous() updates the pointer first and then returns the element.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * means that when you change direction while iterating (i.e., call next() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * then call previous(), or call previous() and then call next()), you'll get
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * back the same element twice.</p>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
   180
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
   181
     * @return the next collation element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public int next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return NULLORDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        NormalizerBase.Mode textMode = text.getMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        // convert the owner's mode to something the Normalizer understands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        NormalizerBase.Mode ownerMode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (textMode != ownerMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            text.setMode(ownerMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        // if buffer contains any decomposed char values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // return their strength orders before continuing in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // the Normalizer's CharacterIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (buffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            if (expIndex < buffer.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                return strengthOrder(buffer[expIndex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        } else if (swapOrder != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (Character.isSupplementaryCodePoint(swapOrder)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                char[] chars = Character.toChars(swapOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                swapOrder = chars[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                return chars[0] << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            int order = swapOrder << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        int ch  = text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // are we at the end of Normalizer's text?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (ch == NormalizerBase.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            return NULLORDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        int value = ordering.getUnicodeOrder(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (value == RuleBasedCollator.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            swapOrder = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return UNMAPPEDCHARVALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        else if (value >= RuleBasedCollator.CONTRACTCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            value = nextContractChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        if (value >= RuleBasedCollator.EXPANDCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            buffer = ordering.getExpandValueList(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            value = buffer[expIndex++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if (ordering.isSEAsianSwapping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            int consonant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            if (isThaiPreVowel(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                consonant = text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                if (isThaiBaseConsonant(consonant)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                    buffer = makeReorderedBuffer(consonant, value, buffer, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    value = buffer[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                    expIndex = 1;
4839
6b3edc448285 5047314: [Col] Collator.compare() runs indefinitely for a certain set of Thai strings
peytoia
parents: 2
diff changeset
   245
                } else if (consonant != NormalizerBase.DONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (isLaoPreVowel(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                consonant = text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (isLaoBaseConsonant(consonant)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    buffer = makeReorderedBuffer(consonant, value, buffer, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    value = buffer[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                    expIndex = 1;
4839
6b3edc448285 5047314: [Col] Collator.compare() runs indefinitely for a certain set of Thai strings
peytoia
parents: 2
diff changeset
   255
                } else if (consonant != NormalizerBase.DONE) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
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
        return strengthOrder(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Get the previous collation element in the string.  <p>This iterator iterates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * over a sequence of collation elements that were built from the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Because there isn't necessarily a one-to-one mapping from characters to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * collation elements, this doesn't mean the same thing as "return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * collation element [or ordering priority] of the previous character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * string".</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>This function updates the iterator's internal pointer to point to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * collation element preceding the one it's currently pointing to and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * returns that element, while next() returns the current element and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * updates the pointer.  This means that when you change direction while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * iterating (i.e., call next() and then call previous(), or call previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * and then call next()), you'll get back the same element twice.</p>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
   277
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 14342
diff changeset
   278
     * @return the previous collation element
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public int previous()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return NULLORDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        NormalizerBase.Mode textMode = text.getMode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // convert the owner's mode to something the Normalizer understands
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        NormalizerBase.Mode ownerMode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (textMode != ownerMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            text.setMode(ownerMode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (buffer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (expIndex > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                return strengthOrder(buffer[--expIndex]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        } else if (swapOrder != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            if (Character.isSupplementaryCodePoint(swapOrder)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                char[] chars = Character.toChars(swapOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                swapOrder = chars[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                return chars[0] << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            int order = swapOrder << 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        int ch = text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (ch == NormalizerBase.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            return NULLORDER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        int value = ordering.getUnicodeOrder(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (value == RuleBasedCollator.UNMAPPED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            swapOrder = UNMAPPEDCHARVALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        } else if (value >= RuleBasedCollator.CONTRACTCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            value = prevContractChar(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (value >= RuleBasedCollator.EXPANDCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            buffer = ordering.getExpandValueList(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            expIndex = buffer.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            value = buffer[--expIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (ordering.isSEAsianSwapping()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            int vowel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            if (isThaiBaseConsonant(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                vowel = text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                if (isThaiPreVowel(vowel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    buffer = makeReorderedBuffer(vowel, value, buffer, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                    expIndex = buffer.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    value = buffer[expIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            if (isLaoBaseConsonant(ch)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                vowel = text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                if (isLaoPreVowel(vowel)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    buffer = makeReorderedBuffer(vowel, value, buffer, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    expIndex = buffer.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    value = buffer[expIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return strengthOrder(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Return the primary component of a collation element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param order the collation element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @return the element's primary component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   361
    public static final int primaryOrder(int order)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        order &= RBCollationTables.PRIMARYORDERMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return (order >>> RBCollationTables.PRIMARYORDERSHIFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * Return the secondary component of a collation element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param order the collation element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @return the element's secondary component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   371
    public static final short secondaryOrder(int order)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        order = order & RBCollationTables.SECONDARYORDERMASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return ((short)(order >> RBCollationTables.SECONDARYORDERSHIFT));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Return the tertiary component of a collation element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @param order the collation element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @return the element's tertiary component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   381
    public static final short tertiaryOrder(int order)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return ((short)(order &= RBCollationTables.TERTIARYORDERMASK));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *  Get the comparison order in the desired strength.  Ignore the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *  differences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *  @param order The order value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    final int strengthOrder(int order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        int s = owner.getStrength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (s == Collator.PRIMARY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            order &= RBCollationTables.PRIMARYDIFFERENCEONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } else if (s == Collator.SECONDARY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            order &= RBCollationTables.SECONDARYDIFFERENCEONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Sets the iterator to point to the collation element corresponding to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * the specified character (the parameter is a CHARACTER offset in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * original string, not an offset into its corresponding sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * collation elements).  The value returned by the next call to next()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * will be the collation element corresponding to the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * in the text.  If that position is in the middle of a contracting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * character sequence, the result of the next call to next() is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * collation element for that sequence.  This means that getOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * is not guaranteed to return the same value as was passed to a preceding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * call to setOffset().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @param newOffset The new character offset into the original text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   419
    @SuppressWarnings("deprecation") // getBeginIndex, getEndIndex and setIndex are deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public void setOffset(int newOffset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (newOffset < text.getBeginIndex()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                || newOffset >= text.getEndIndex()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    text.setIndexOnly(newOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                int c = text.setIndex(newOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                // if the desired character isn't used in a contracting character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                // sequence, bypass all the backing-up logic-- we're sitting on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                // the right character already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                if (ordering.usedInContractSeq(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    // walk backwards through the string until we see a character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    // that DOESN'T participate in a contracting character sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    while (ordering.usedInContractSeq(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        c = text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                    // now walk forward using this object's next() method until
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                    // we pass the starting point and set our current position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    // to the beginning of the last "character" before or at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    // our starting position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                    int last = text.getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    while (text.getIndex() <= newOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                        last = text.getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                        next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    text.setIndexOnly(last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    // we don't need this, since last is the last index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    // that is the starting of the contraction which encompass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    // newOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    // text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Returns the character offset in the original text corresponding to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * collation element.  (That is, getOffset() returns the position in the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * corresponding to the collation element that will be returned by the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * call to next().)  This value will always be the index of the FIRST character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * corresponding to the collation element (a contracting character sequence is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * when two or more characters all correspond to the same collation element).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * This means if you do setOffset(x) followed immediately by getOffset(), getOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * won't necessarily return x.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @return The character offset in the original text corresponding to the collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * element that will be returned by the next call to next().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public int getOffset()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        return (text != null) ? text.getIndex() : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Return the maximum length of any expansion sequences that end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * with the specified comparison order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param order a collation order returned by previous or next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @return the maximum length of any expansion sequences ending
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *         with the specified order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public int getMaxExpansion(int order)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return ordering.getMaxExpansion(order);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * Set a new string over which to iterate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @param source  the new source text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public void setText(String source)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        NormalizerBase.Mode mode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            text = new NormalizerBase(source, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            text.setMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            text.setText(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * Set a new string over which to iterate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * @param source  the new source text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    public void setText(CharacterIterator source)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        NormalizerBase.Mode mode =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            CollatorUtilities.toNormalizerMode(owner.getDecomposition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (text == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            text = new NormalizerBase(source, mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            text.setMode(mode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            text.setText(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    //============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    // privates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    //============================================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Determine if a character is a Thai vowel (which sorts after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * its base consonant).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   543
    private static final boolean isThaiPreVowel(int ch) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        return (ch >= 0x0e40) && (ch <= 0x0e44);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * Determine if a character is a Thai base consonant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   550
    private static final boolean isThaiBaseConsonant(int ch) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return (ch >= 0x0e01) && (ch <= 0x0e2e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Determine if a character is a Lao vowel (which sorts after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * its base consonant).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   558
    private static final boolean isLaoPreVowel(int ch) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return (ch >= 0x0ec0) && (ch <= 0x0ec4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Determine if a character is a Lao base consonant
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   565
    private static final boolean isLaoBaseConsonant(int ch) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return (ch >= 0x0e81) && (ch <= 0x0eae);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * This method produces a buffer which contains the collation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * elements for the two characters, with colFirst's values preceding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * another character's.  Presumably, the other character precedes colFirst
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * in logical order (otherwise you wouldn't need this method would you?).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * The assumption is that the other char's value(s) have already been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * computed.  If this char has a single element it is passed to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * method as lastValue, and lastExpansion is null.  If it has an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * expansion it is passed in lastExpansion, and colLastValue is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    private int[] makeReorderedBuffer(int colFirst,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                      int lastValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                      int[] lastExpansion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                      boolean forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        int[] result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        int firstValue = ordering.getUnicodeOrder(colFirst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (firstValue >= RuleBasedCollator.CONTRACTCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            firstValue = forward? nextContractChar(colFirst) : prevContractChar(colFirst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        int[] firstExpansion = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (firstValue >= RuleBasedCollator.EXPANDCHARINDEX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            firstExpansion = ordering.getExpandValueList(firstValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (!forward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            int temp1 = firstValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            firstValue = lastValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            lastValue = temp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            int[] temp2 = firstExpansion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            firstExpansion = lastExpansion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            lastExpansion = temp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        if (firstExpansion == null && lastExpansion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            result = new int [2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            result[0] = firstValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            result[1] = lastValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            int firstLength = firstExpansion==null? 1 : firstExpansion.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            int lastLength = lastExpansion==null? 1 : lastExpansion.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            result = new int[firstLength + lastLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (firstExpansion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                result[0] = firstValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                System.arraycopy(firstExpansion, 0, result, 0, firstLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            if (lastExpansion == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                result[firstLength] = lastValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                System.arraycopy(lastExpansion, 0, result, firstLength, lastLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *  Check if a comparison order is ignorable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *  @return true if a character is ignorable, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   637
    static final boolean isIgnorable(int order)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        return ((primaryOrder(order) == 0) ? true : false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Get the ordering priority of the next contracting character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * @param ch the starting character of a contracting character token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @return the next contracting character's ordering.  Returns NULLORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * if the end of string is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    private int nextContractChar(int ch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        // First get the ordering of this single character,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        // which is always the first element in the list
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   653
        Vector<EntryPair> list = ordering.getContractValues(ch);
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   654
        EntryPair pair = list.firstElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        int order = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        // find out the length of the longest contracting character sequence in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        // There's logic in the builder code to make sure the longest sequence is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // the last.
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   660
        pair = list.lastElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        int maxLength = pair.entryName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        // (the Normalizer is cloned here so that the seeking we do in the next loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        // won't affect our real position in the text)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        NormalizerBase tempText = (NormalizerBase)text.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        // extract the next maxLength characters in the string (we have to do this using the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        // Normalizer to ensure that our offsets correspond to those the rest of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        // iterator is using) and store it in "fragment".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        tempText.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        key.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        int c = tempText.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        while (maxLength > 0 && c != NormalizerBase.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            if (Character.isSupplementaryCodePoint(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                key.append(Character.toChars(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                maxLength -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                key.append((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                --maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            c = tempText.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        String fragment = key.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        // now that we have that fragment, iterate through this list looking for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        // longest sequence that matches the characters in the actual text.  (maxLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        // is used here to keep track of the length of the longest sequence)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // Upon exit from this loop, maxLength will contain the length of the matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        // sequence and order will contain the collation-element value corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        // to this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        maxLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        for (int i = list.size() - 1; i > 0; i--) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   692
            pair = list.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            if (!pair.fwd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            if (fragment.startsWith(pair.entryName) && pair.entryName.length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                    > maxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                maxLength = pair.entryName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                order = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // seek our current iteration position to the end of the matching sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        // and return the appropriate collation-element value (if there was no matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        // sequence, we're already seeked to the right position and order already contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        // the correct collation-element value for the single character)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        while (maxLength > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            c = text.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            maxLength -= Character.charCount(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Get the ordering priority of the previous contracting character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @param ch the starting character of a contracting character token
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @return the next contracting character's ordering.  Returns NULLORDER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * if the end of string is reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    private int prevContractChar(int ch)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        // This function is identical to nextContractChar(), except that we've
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        // switched things so that the next() and previous() calls on the Normalizer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        // are switched and so that we skip entry pairs with the fwd flag turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        // rather than off.  Notice that we still use append() and startsWith() when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        // working on the fragment.  This is because the entry pairs that are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        // in reverse iteration have their names reversed already.
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   729
        Vector<EntryPair> list = ordering.getContractValues(ch);
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   730
        EntryPair pair = list.firstElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        int order = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   733
        pair = list.lastElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        int maxLength = pair.entryName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        NormalizerBase tempText = (NormalizerBase)text.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        tempText.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        key.setLength(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        int c = tempText.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        while (maxLength > 0 && c != NormalizerBase.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            if (Character.isSupplementaryCodePoint(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                key.append(Character.toChars(c));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                maxLength -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                key.append((char)c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                --maxLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            c = tempText.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        String fragment = key.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        maxLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        for (int i = list.size() - 1; i > 0; i--) {
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   755
            pair = list.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if (pair.fwd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            if (fragment.startsWith(pair.entryName) && pair.entryName.length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    > maxLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                maxLength = pair.entryName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                order = pair.value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        while (maxLength > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            c = text.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            maxLength -= Character.charCount(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        return order;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   773
    static final int UNMAPPEDCHARVALUE = 0x7FFF0000;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    private NormalizerBase text = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    private int[] buffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    private int expIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    private StringBuffer key = new StringBuffer(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    private int swapOrder = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private RBCollationTables ordering;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    private RuleBasedCollator owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
}