1 7 8 package com.ibm.icu.impl; 9 10 import com.ibm.icu.text.*; 11 12 13 17 18 public final class UCharArrayIterator extends UCharacterIterator { 19 private final char[] text; 20 private final int start; 21 private final int limit; 22 private int pos; 23 24 public UCharArrayIterator(char[] text, int start, int limit) { 25 if (start < 0 || limit > text.length || start > limit) { 26 throw new IllegalArgumentException ("start: " + start + " or limit: " 27 + limit + " out of range [0, " 28 + text.length + ")"); 29 } 30 this.text = text; 31 this.start = start; 32 this.limit = limit; 33 34 this.pos = start; 35 } 36 37 public int current() { 38 return pos < limit ? text[pos] : DONE; 39 } 40 41 public int getLength() { 42 return limit - start; 43 } 44 45 public int getIndex() { 46 return pos - start; 47 } 48 49 public int next() { 50 return pos < limit ? text[pos++] : DONE; 51 } 52 53 public int previous() { 54 return pos > start ? text[--pos] : DONE; 55 } 56 57 public void setIndex(int index) { 58 if (index < 0 || index > limit - start) { 59 throw new IndexOutOfBoundsException ("index: " + index + 60 " out of range [0, " 61 + (limit - start) + ")"); 62 } 63 pos = start + index; 64 } 65 66 public int getText(char[] fillIn, int offset) { 67 int len = limit - start; 68 System.arraycopy(text, start, fillIn, offset, len); 69 return len; 70 } 71 72 77 public Object clone(){ 78 try { 79 return super.clone(); 80 } catch (CloneNotSupportedException e) { 81 return null; } 83 } 84 } | Popular Tags |