1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2017 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 package ohos.global.icu.impl; 5 6 import java.text.CharacterIterator; 7 8 /** 9 * Implement the Java CharacterIterator interface on a CharSequence. 10 * Intended for internal use by ICU only. 11 * @hide exposed on OHOS 12 */ 13 public class CSCharacterIterator implements CharacterIterator { 14 15 private int index; 16 private CharSequence seq; 17 18 19 /** 20 * Constructor. 21 * @param text The CharSequence to iterate over. 22 */ CSCharacterIterator(CharSequence text)23 public CSCharacterIterator(CharSequence text) { 24 if (text == null) { 25 throw new NullPointerException(); 26 } 27 seq = text; 28 index = 0; 29 } 30 31 /** @{inheritDoc} */ 32 @Override first()33 public char first() { 34 index = 0; 35 return current(); 36 } 37 38 /** @{inheritDoc} */ 39 @Override last()40 public char last() { 41 index = seq.length(); 42 return previous(); 43 } 44 45 /** @{inheritDoc} */ 46 @Override current()47 public char current() { 48 if (index == seq.length()) { 49 return DONE; 50 } 51 return seq.charAt(index); 52 } 53 54 /** @{inheritDoc} */ 55 @Override next()56 public char next() { 57 if (index < seq.length()) { 58 ++index; 59 } 60 return current(); 61 } 62 63 /** @{inheritDoc} */ 64 @Override previous()65 public char previous() { 66 if (index == 0) { 67 return DONE; 68 } 69 --index; 70 return current(); 71 } 72 73 /** @{inheritDoc} */ 74 @Override setIndex(int position)75 public char setIndex(int position) { 76 if (position < 0 || position > seq.length()) { 77 throw new IllegalArgumentException(); 78 } 79 index = position; 80 return current(); 81 } 82 83 /** @{inheritDoc} */ 84 @Override getBeginIndex()85 public int getBeginIndex() { 86 return 0; 87 } 88 89 /** @{inheritDoc} */ 90 @Override getEndIndex()91 public int getEndIndex() { 92 return seq.length(); 93 } 94 95 /** @{inheritDoc} */ 96 @Override getIndex()97 public int getIndex() { 98 return index; 99 } 100 101 /** @{inheritDoc} */ 102 @Override clone()103 public Object clone() { 104 CSCharacterIterator copy = new CSCharacterIterator(seq); 105 copy.setIndex(index); 106 return copy; 107 } 108 } 109