1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/compact/src/main/java/java/text/CharacterIterator.java Thu Oct 03 15:40:35 2013 +0200
1.3 @@ -0,0 +1,193 @@
1.4 +/*
1.5 + * Copyright (c) 1996, 2000, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +/*
1.30 + * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
1.31 + * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
1.32 + *
1.33 + * The original version of this source code and documentation
1.34 + * is copyrighted and owned by Taligent, Inc., a wholly-owned
1.35 + * subsidiary of IBM. These materials are provided under terms
1.36 + * of a License Agreement between Taligent and Sun. This technology
1.37 + * is protected by multiple US and International patents.
1.38 + *
1.39 + * This notice and attribution to Taligent may not be removed.
1.40 + * Taligent is a registered trademark of Taligent, Inc.
1.41 + *
1.42 + */
1.43 +
1.44 +package java.text;
1.45 +
1.46 +
1.47 +/**
1.48 + * This interface defines a protocol for bidirectional iteration over text.
1.49 + * The iterator iterates over a bounded sequence of characters. Characters
1.50 + * are indexed with values beginning with the value returned by getBeginIndex() and
1.51 + * continuing through the value returned by getEndIndex()-1.
1.52 + * <p>
1.53 + * Iterators maintain a current character index, whose valid range is from
1.54 + * getBeginIndex() to getEndIndex(); the value getEndIndex() is included to allow
1.55 + * handling of zero-length text ranges and for historical reasons.
1.56 + * The current index can be retrieved by calling getIndex() and set directly
1.57 + * by calling setIndex(), first(), and last().
1.58 + * <p>
1.59 + * The methods previous() and next() are used for iteration. They return DONE if
1.60 + * they would move outside the range from getBeginIndex() to getEndIndex() -1,
1.61 + * signaling that the iterator has reached the end of the sequence. DONE is
1.62 + * also returned by other methods to indicate that the current index is
1.63 + * outside this range.
1.64 + *
1.65 + * <P>Examples:<P>
1.66 + *
1.67 + * Traverse the text from start to finish
1.68 + * <pre>
1.69 + * public void traverseForward(CharacterIterator iter) {
1.70 + * for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
1.71 + * processChar(c);
1.72 + * }
1.73 + * }
1.74 + * </pre>
1.75 + *
1.76 + * Traverse the text backwards, from end to start
1.77 + * <pre>
1.78 + * public void traverseBackward(CharacterIterator iter) {
1.79 + * for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
1.80 + * processChar(c);
1.81 + * }
1.82 + * }
1.83 + * </pre>
1.84 + *
1.85 + * Traverse both forward and backward from a given position in the text.
1.86 + * Calls to notBoundary() in this example represents some
1.87 + * additional stopping criteria.
1.88 + * <pre>
1.89 + * public void traverseOut(CharacterIterator iter, int pos) {
1.90 + * for (char c = iter.setIndex(pos);
1.91 + * c != CharacterIterator.DONE && notBoundary(c);
1.92 + * c = iter.next()) {
1.93 + * }
1.94 + * int end = iter.getIndex();
1.95 + * for (char c = iter.setIndex(pos);
1.96 + * c != CharacterIterator.DONE && notBoundary(c);
1.97 + * c = iter.previous()) {
1.98 + * }
1.99 + * int start = iter.getIndex();
1.100 + * processSection(start, end);
1.101 + * }
1.102 + * </pre>
1.103 + *
1.104 + * @see StringCharacterIterator
1.105 + * @see AttributedCharacterIterator
1.106 + */
1.107 +
1.108 +public interface CharacterIterator extends Cloneable
1.109 +{
1.110 +
1.111 + /**
1.112 + * Constant that is returned when the iterator has reached either the end
1.113 + * or the beginning of the text. The value is '\\uFFFF', the "not a
1.114 + * character" value which should not occur in any valid Unicode string.
1.115 + */
1.116 + public static final char DONE = '\uFFFF';
1.117 +
1.118 + /**
1.119 + * Sets the position to getBeginIndex() and returns the character at that
1.120 + * position.
1.121 + * @return the first character in the text, or DONE if the text is empty
1.122 + * @see #getBeginIndex()
1.123 + */
1.124 + public char first();
1.125 +
1.126 + /**
1.127 + * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
1.128 + * and returns the character at that position.
1.129 + * @return the last character in the text, or DONE if the text is empty
1.130 + * @see #getEndIndex()
1.131 + */
1.132 + public char last();
1.133 +
1.134 + /**
1.135 + * Gets the character at the current position (as returned by getIndex()).
1.136 + * @return the character at the current position or DONE if the current
1.137 + * position is off the end of the text.
1.138 + * @see #getIndex()
1.139 + */
1.140 + public char current();
1.141 +
1.142 + /**
1.143 + * Increments the iterator's index by one and returns the character
1.144 + * at the new index. If the resulting index is greater or equal
1.145 + * to getEndIndex(), the current index is reset to getEndIndex() and
1.146 + * a value of DONE is returned.
1.147 + * @return the character at the new position or DONE if the new
1.148 + * position is off the end of the text range.
1.149 + */
1.150 + public char next();
1.151 +
1.152 + /**
1.153 + * Decrements the iterator's index by one and returns the character
1.154 + * at the new index. If the current index is getBeginIndex(), the index
1.155 + * remains at getBeginIndex() and a value of DONE is returned.
1.156 + * @return the character at the new position or DONE if the current
1.157 + * position is equal to getBeginIndex().
1.158 + */
1.159 + public char previous();
1.160 +
1.161 + /**
1.162 + * Sets the position to the specified position in the text and returns that
1.163 + * character.
1.164 + * @param position the position within the text. Valid values range from
1.165 + * getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown
1.166 + * if an invalid value is supplied.
1.167 + * @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
1.168 + */
1.169 + public char setIndex(int position);
1.170 +
1.171 + /**
1.172 + * Returns the start index of the text.
1.173 + * @return the index at which the text begins.
1.174 + */
1.175 + public int getBeginIndex();
1.176 +
1.177 + /**
1.178 + * Returns the end index of the text. This index is the index of the first
1.179 + * character following the end of the text.
1.180 + * @return the index after the last character in the text
1.181 + */
1.182 + public int getEndIndex();
1.183 +
1.184 + /**
1.185 + * Returns the current index.
1.186 + * @return the current index.
1.187 + */
1.188 + public int getIndex();
1.189 +
1.190 + /**
1.191 + * Create a copy of this iterator
1.192 + * @return A copy of this
1.193 + */
1.194 + public Object clone();
1.195 +
1.196 +}