2 *******************************************************************************
\r
3 * Copyright (C) 1996-2006, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
9 // NOTE: This class is identical to java.text.StringCharacterIterator
\r
10 // in JDK 1.2. It's copied here because the JDK 1.1 version of
\r
11 // StringCharacterIterator has a bug that prevents it from working
\r
12 // right with RuleBasedBreakIterator. This class is unnecessary
\r
13 // when using RuleBasedBreakIterator with JDK 1.2.
\r
15 package com.ibm.icu.text;
\r
16 import java.text.CharacterIterator;
\r
19 * <code>StringCharacterIterator</code> implements the
\r
20 * <code>CharacterIterater</code> protocol for a <code>String</code>.
\r
21 * The <code>StringCharacterIterator</code> class iterates over the
\r
22 * entire <code>String</code>.
\r
24 * @see CharacterIterator
\r
25 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
28 public final class StringCharacterIterator implements CharacterIterator
\r
30 private String text;
\r
33 // invariant: begin <= pos <= end
\r
37 * Constructs an iterator with an initial index of 0.
\r
38 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
40 public StringCharacterIterator(String text)
\r
46 * Constructs an iterator with the specified initial index.
\r
48 * @param text The String to be iterated over
\r
49 * @param pos Initial iterator position
\r
50 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
52 public StringCharacterIterator(String text, int pos)
\r
54 this(text, 0, text.length(), pos);
\r
58 * Constructs an iterator over the given range of the given string, with the
\r
59 * index set at the specified position.
\r
61 * @param text The String to be iterated over
\r
62 * @param begin Index of the first character
\r
63 * @param end Index of the character following the last character
\r
64 * @param pos Initial iterator position
\r
65 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
67 public StringCharacterIterator(String text, int begin, int end, int pos) {
\r
69 throw new NullPointerException();
\r
73 if (begin < 0 || begin > end || end > text.length()) {
\r
74 throw new IllegalArgumentException("Invalid substring range");
\r
77 if (pos < begin || pos > end) {
\r
78 throw new IllegalArgumentException("Invalid position");
\r
87 * Reset this iterator to point to a new string. This package-visible
\r
88 * method is used by other java.text classes that want to avoid allocating
\r
89 * new StringCharacterIterator objects every time their setText method
\r
92 * @param text The String to be iterated over
\r
93 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
95 public void setText(String text) {
\r
97 throw new NullPointerException();
\r
101 this.end = text.length();
\r
106 * Implements CharacterIterator.first() for String.
\r
107 * @see CharacterIterator#first
\r
108 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
110 public char first()
\r
117 * Implements CharacterIterator.last() for String.
\r
118 * @see CharacterIterator#last
\r
119 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
123 if (end != begin) {
\r
132 * Implements CharacterIterator.setIndex() for String.
\r
133 * @see CharacterIterator#setIndex
\r
134 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
136 public char setIndex(int p)
\r
138 if (p < begin || p > end) {
\r
139 throw new IllegalArgumentException("Invalid index");
\r
146 * Implements CharacterIterator.current() for String.
\r
147 * @see CharacterIterator#current
\r
148 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
150 public char current()
\r
152 if (pos >= begin && pos < end) {
\r
153 return text.charAt(pos);
\r
161 * Implements CharacterIterator.next() for String.
\r
162 * @see CharacterIterator#next
\r
163 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
167 if (pos < end - 1) {
\r
169 return text.charAt(pos);
\r
178 * Implements CharacterIterator.previous() for String.
\r
179 * @see CharacterIterator#previous
\r
180 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
182 public char previous()
\r
186 return text.charAt(pos);
\r
194 * Implements CharacterIterator.getBeginIndex() for String.
\r
195 * @see CharacterIterator#getBeginIndex
\r
196 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
198 public int getBeginIndex()
\r
204 * Implements CharacterIterator.getEndIndex() for String.
\r
205 * @see CharacterIterator#getEndIndex
\r
206 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
208 public int getEndIndex()
\r
214 * Implements CharacterIterator.getIndex() for String.
\r
215 * @see CharacterIterator#getIndex
\r
216 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
218 public int getIndex()
\r
224 * Compares the equality of two StringCharacterIterator objects.
\r
225 * @param obj the StringCharacterIterator object to be compared with.
\r
226 * @return true if the given obj is the same as this
\r
227 * StringCharacterIterator object; false otherwise.
\r
228 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
230 public boolean equals(Object obj)
\r
235 if (!(obj instanceof StringCharacterIterator)) {
\r
239 StringCharacterIterator that = (StringCharacterIterator) obj;
\r
241 if (hashCode() != that.hashCode()) {
\r
244 if (!text.equals(that.text)) {
\r
247 if (pos != that.pos || begin != that.begin || end != that.end) {
\r
254 * Computes a hashcode for this iterator.
\r
255 * @return A hash code
\r
256 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
258 public int hashCode()
\r
260 return text.hashCode() ^ pos ^ begin ^ end;
\r
264 * Creates a copy of this iterator.
\r
265 * @return A copy of this
\r
266 * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
\r
268 public Object clone()
\r
271 StringCharacterIterator other
\r
272 = (StringCharacterIterator) super.clone();
\r
275 catch (CloneNotSupportedException e) {
\r
276 throw new IllegalStateException();
\r