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