jdk/src/java.base/share/classes/sun/text/normalizer/UCharacterIterator.java
author peytoia
Wed, 15 Jul 2015 11:05:51 +0900
changeset 31680 88c53c2293b4
parent 30655 d83f50188ca9
permissions -rw-r--r--
8032446: Support Unicode 7.0.0 in JDK 9 8130889: Missing "@since 1.8" tags in j.l.Character.java Reviewed-by: naoto, okutsu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
     2
 * Copyright (c) 2003, 2015, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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
 *******************************************************************************
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
    28
 * Copyright (C) 1996-2014, International Business Machines Corporation and    *
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
    29
 * others. All Rights Reserved.                                                *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *******************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
package sun.text.normalizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.text.CharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Abstract class that defines an API for iteration on text objects.This is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * interface for forward and backward iteration and random access into a text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * object. Forward iteration is done with post-increment and backward iteration
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * is done with pre-decrement semantics, while the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>java.text.CharacterIterator</code> interface methods provided forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * iteration with "pre-increment" and backward iteration with pre-decrement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * semantics. This API is more efficient for forward iteration over code points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The other major difference is that this API can do both code unit and code point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * iteration, <code>java.text.CharacterIterator</code> can only iterate over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * code units and is limited to BMP (0 - 0xFFFF)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author Ram
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
public abstract class UCharacterIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                      implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Protected default constructor for the subclasses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    protected UCharacterIterator(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Indicator that we have reached the ends of the UTF16 text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Moved from UForwardCharacterIterator.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public static final int DONE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    // static final methods ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns a <code>UCharacterIterator</code> object given a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * source string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param source a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return UCharacterIterator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @exception IllegalArgumentException if the argument is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final UCharacterIterator getInstance(String source){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return new ReplaceableUCharacterIterator(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Returns a <code>UCharacterIterator</code> object given a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * source StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param source an string buffer of UTF-16 code units
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return UCharacterIterator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @exception IllegalArgumentException if the argument is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final UCharacterIterator getInstance(StringBuffer source){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return new ReplaceableUCharacterIterator(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
    94
   /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Returns a <code>UCharacterIterator</code> object given a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * CharacterIterator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param source a valid CharacterIterator object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return UCharacterIterator object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @exception IllegalArgumentException if the argument is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final UCharacterIterator getInstance(CharacterIterator source){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return new CharacterIteratorWrapper(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    // public methods ----------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Returns the length of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return length of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public abstract int getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Gets the current index in text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @return current index in text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public abstract int getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Returns the UTF16 code unit at index, and increments to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * code unit (post-increment semantics).  If index is out of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * range, DONE is returned, and the iterator is reset to the limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the next UTF16 code unit, or DONE if the index is at the limit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public abstract int next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Returns the code point at index, and increments to the next code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * point (post-increment semantics).  If index does not point to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * valid surrogate pair, the behavior is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <code>next()</code>.  Otherwise the iterator is incremented past
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the surrogate pair, and the code point represented by the pair
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return the next codepoint in text, or DONE if the index is at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *         the limit of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public int nextCodePoint(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int ch1 = next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if(UTF16.isLeadSurrogate((char)ch1)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            int ch2 = next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            if(UTF16.isTrailSurrogate((char)ch2)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                return UCharacterProperty.getRawSupplementary((char)ch1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                                                              (char)ch2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            }else if (ch2 != DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                // unmatched surrogate so back out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return ch1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Decrement to the position of the previous code unit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * text, and return it (pre-decrement semantics).  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * resulting index is less than 0, the index is reset to 0 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * DONE is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @return the previous code unit in the text, or DONE if the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *         index is before the start of the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public abstract int previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   170
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   171
    /**
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   172
     * Retreat to the start of the previous code point in the text,
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   173
     * and return it (pre-decrement semantics).  If the index is not
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   174
     * preceeded by a valid surrogate pair, the behavior is the same
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   175
     * as <code>previous()</code>.  Otherwise the iterator is
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   176
     * decremented to the start of the surrogate pair, and the code
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   177
     * point represented by the pair is returned.
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   178
     * @return the previous code point in the text, or DONE if the new
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   179
     *         index is before the start of the text.
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   180
     * @stable ICU 2.4
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   181
     */
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   182
    public int previousCodePoint(){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   183
        int ch1 = previous();
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   184
        if(UTF16.isTrailSurrogate((char)ch1)){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   185
            int ch2 = previous();
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   186
            if(UTF16.isLeadSurrogate((char)ch2)){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   187
                return UCharacterProperty.getRawSupplementary((char)ch2,
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   188
                                                              (char)ch1);
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   189
            }else if (ch2 != DONE) {
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   190
                //unmatched trail surrogate so back out
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   191
                next();
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   192
            }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   193
        }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   194
        return ch1;
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   195
    }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   196
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Sets the index to the specified index in the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param index the index within the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception IndexOutOfBoundsException is thrown if an invalid index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *            supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public abstract void setIndex(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   206
    /**
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   207
     * Sets the current index to the start.
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   208
     * @stable ICU 2.4
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   209
     */
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   210
    public void setToStart() {
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   211
        setIndex(0);
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   212
    }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   213
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Fills the buffer with the underlying text storage of the iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * If the buffer capacity is not enough a exception is thrown. The capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * of the fill in buffer should at least be equal to length of text in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * iterator obtained by calling <code>getLength()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <b>Usage:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28059
diff changeset
   221
     * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *         UChacterIterator iter = new UCharacterIterator.getInstance(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *         char[] buf = new char[iter.getLength()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *         iter.getText(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *         OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *         char[] buf= new char[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *         int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *         for(;;){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *             try{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *                 len = iter.getText(buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *                 break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *             }catch(IndexOutOfBoundsException e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *                 buf = new char[iter.getLength()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *             }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *         }
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 28059
diff changeset
   237
     * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @param fillIn an array of chars to fill with the underlying UTF-16 code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *         units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param offset the position within the array to start putting the data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return the number of code units added to fillIn, as a convenience
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   243
     * @exception IndexOutOfBoundsException exception if there is not enough
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   244
     *            room after offset in the array, or if offset < 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public abstract int getText(char[] fillIn, int offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Convenience override for <code>getText(char[], int)</code> that provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * an offset of 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @param fillIn an array of chars to fill with the underlying UTF-16 code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *         units.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @return the number of code units added to fillIn, as a convenience
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   255
     * @exception IndexOutOfBoundsException exception if there is not enough
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *            room in the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public final int getText(char[] fillIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        return getText(fillIn, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   264
     * Convenience method for returning the underlying text storage as a string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @return the underlying text storage in the iterator as a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        char[] text = new char[getLength()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        getText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return new String(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    /**
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   275
     * Moves the current position by the number of code points
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   276
     * specified, either forward or backward depending on the sign of
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   277
     * delta (positive or negative respectively). If the current index
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   278
     * is at a trail surrogate then the first adjustment is by code
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   279
     * unit, and the remaining adjustments are by code points.  If the
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   280
     * resulting index would be less than zero, the index is set to
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   281
     * zero, and if the resulting index would be greater than limit,
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   282
     * the index is set to limit.
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   283
     * @param delta the number of code units to move the current index.
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   284
     * @return the new index
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   285
     * @exception IndexOutOfBoundsException is thrown if an invalid delta is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *            supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
31680
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   290
    public int moveCodePointIndex(int delta){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   291
        if(delta>0){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   292
            while(delta>0 && nextCodePoint() != DONE){delta--;}
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   293
        }else{
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   294
            while(delta<0 && previousCodePoint() != DONE){delta++;}
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   295
        }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   296
        if(delta!=0){
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   297
            throw new IndexOutOfBoundsException();
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   298
        }
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   299
88c53c2293b4 8032446: Support Unicode 7.0.0 in JDK 9
peytoia
parents: 30655
diff changeset
   300
        return getIndex();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Creates a copy of this iterator, independent from other iterators.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * If it is not possible to clone the iterator, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return copy of this iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @stable ICU 2.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    public Object clone() throws CloneNotSupportedException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
}