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