1 7 package com.ibm.icu.impl; 8 9 import com.ibm.icu.text.UCharacterIterator; 10 11 16 public final class StringUCharacterIterator extends UCharacterIterator 19 { 20 21 23 27 public StringUCharacterIterator(String str) 28 { 29 if (str == null) { 30 throw new IllegalArgumentException (); 31 } 32 m_text_ = str; 33 m_currentIndex_ = 0; 34 } 35 36 39 public StringUCharacterIterator() 40 { 41 m_text_ = ""; 42 m_currentIndex_ = 0; 43 } 44 45 47 52 public Object clone() 54 { 55 try { 56 return super.clone(); 57 } catch (CloneNotSupportedException e) { 58 return null; } 60 } 61 66 public int current() 67 { 68 if (m_currentIndex_ < m_text_.length()) { 69 return m_text_.charAt(m_currentIndex_); 70 } 71 return DONE; 72 } 73 74 75 79 public int getLength() 80 { 81 return m_text_.length(); 82 } 83 84 88 public int getIndex() 89 { 90 return m_currentIndex_; 91 } 92 93 102 public int next() 103 { 104 if (m_currentIndex_ < m_text_.length()) 105 { 106 return m_text_.charAt(m_currentIndex_ ++); 107 } 108 return DONE; 109 } 110 111 112 120 public int previous() 121 { 122 if (m_currentIndex_ > 0) { 123 return m_text_.charAt(-- m_currentIndex_); 124 } 125 return DONE; 126 } 127 128 136 public void setIndex(int currentIndex) throws IndexOutOfBoundsException 137 { 138 if (currentIndex < 0 || currentIndex > m_text_.length()) { 139 throw new IndexOutOfBoundsException (); 140 } 141 m_currentIndex_ = currentIndex; 142 } 143 144 178 public int getText(char[] fillIn, int offset) 180 { 181 int length = m_text_.length(); 182 if (offset < 0 || offset + length > fillIn.length) { 183 throw new IndexOutOfBoundsException (Integer.toString(length)); 184 } 185 m_text_.getChars(0, length, fillIn, offset); 186 return length; 187 } 188 194 public String getText() 195 { 196 return m_text_; 197 } 198 199 206 public void setText(String text) 207 { 208 if (text == null) { 209 throw new NullPointerException (); 210 } 211 m_text_ = text; 212 m_currentIndex_ = 0; 213 } 214 215 217 220 private String m_text_; 221 224 private int m_currentIndex_; 225 226 } 227 | Popular Tags |