1 7 package com.ibm.icu.impl; 8 9 import com.ibm.icu.text.*; 10 import com.ibm.icu.text.Replaceable; 11 import com.ibm.icu.text.ReplaceableString; 12 import com.ibm.icu.text.UTF16; 13 14 24 public class ReplaceableUCharacterIterator extends UCharacterIterator { 25 26 28 32 public ReplaceableUCharacterIterator(Replaceable replaceable){ 33 if(replaceable==null){ 34 throw new IllegalArgumentException (); 35 } 36 this.replaceable = replaceable; 37 this.currentIndex = 0; 38 } 39 40 44 public ReplaceableUCharacterIterator(String str){ 45 if(str==null){ 46 throw new IllegalArgumentException (); 47 } 48 this.replaceable = new ReplaceableString(str); 49 this.currentIndex = 0; 50 } 51 52 56 public ReplaceableUCharacterIterator(StringBuffer buf){ 57 if(buf==null){ 58 throw new IllegalArgumentException (); 59 } 60 this.replaceable = new ReplaceableString(buf); 61 this.currentIndex = 0; 62 } 63 64 66 71 public Object clone(){ 72 try { 73 return super.clone(); 74 } catch (CloneNotSupportedException e) { 75 return null; } 77 } 78 79 83 public int current(){ 84 if (currentIndex < replaceable.length()) { 85 return replaceable.charAt(currentIndex); 86 } 87 return DONE; 88 } 89 90 94 public int currentCodePoint(){ 95 99 int ch = current(); 100 if(UTF16.isLeadSurrogate((char)ch)){ 101 next(); 103 int ch2 = current(); 106 previous(); 108 109 if(UTF16.isTrailSurrogate((char)ch2)){ 110 return UCharacterProperty.getRawSupplementary( 112 (char)ch,(char)ch2 113 ); 114 } 115 } 116 return ch; 117 } 118 119 123 public int getLength(){ 124 return replaceable.length(); 125 } 126 127 131 public int getIndex(){ 132 return currentIndex; 133 } 134 135 143 public int next(){ 144 if (currentIndex < replaceable.length()) { 145 return replaceable.charAt(currentIndex++); 146 } 147 return DONE; 148 } 149 150 151 159 public int previous(){ 160 if (currentIndex > 0) { 161 return replaceable.charAt(--currentIndex); 162 } 163 return DONE; 164 } 165 166 176 public void setIndex(int currentIndex) throws IndexOutOfBoundsException { 177 if (currentIndex < 0 || currentIndex > replaceable.length()) { 178 throw new IndexOutOfBoundsException (); 179 } 180 this.currentIndex = currentIndex; 181 } 182 183 public int getText(char[] fillIn, int offset){ 184 int length = replaceable.length(); 185 if(offset < 0 || offset + length > fillIn.length){ 186 throw new IndexOutOfBoundsException (Integer.toString(length)); 187 } 188 replaceable.getChars(0,length,fillIn,offset); 189 return length; 190 } 191 192 194 197 private Replaceable replaceable; 198 201 private int currentIndex; 202 203 } 204 | Popular Tags |