1/* GENERATED SOURCE. DO NOT MODIFY. */ 2// © 2016 and later: Unicode, Inc. and others. 3// License & terms of use: http://www.unicode.org/copyright.html#License 4/* 5 ******************************************************************************* 6 * Copyright (C) 1996-2010, International Business Machines Corporation and * 7 * others. All Rights Reserved. * 8 ******************************************************************************* 9 */ 10 11package android.icu.impl; 12 13import java.text.CharacterIterator; 14 15import android.icu.text.UCharacterIterator; 16 17/** 18 * This class is a wrapper around UCharacterIterator and implements the 19 * CharacterIterator protocol 20 * @author ram 21 * @hide Only a subset of ICU is exposed in Android 22 */ 23public class UCharacterIteratorWrapper implements CharacterIterator{ 24 25 public UCharacterIteratorWrapper(UCharacterIterator iter){ 26 this.iterator = iter; 27 } 28 29 private UCharacterIterator iterator; 30 31 32 /** 33 * Sets the position to getBeginIndex() and returns the character at that 34 * position. 35 * @return the first character in the text, or DONE if the text is empty 36 * @see #getBeginIndex() 37 */ 38 @Override 39 public char first(){ 40 //UCharacterIterator always iterates from 0 to length 41 iterator.setToStart(); 42 return (char)iterator.current(); 43 } 44 45 /** 46 * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) 47 * and returns the character at that position. 48 * @return the last character in the text, or DONE if the text is empty 49 * @see #getEndIndex() 50 */ 51 @Override 52 public char last(){ 53 iterator.setToLimit(); 54 return (char)iterator.previous(); 55 } 56 57 /** 58 * Gets the character at the current position (as returned by getIndex()). 59 * @return the character at the current position or DONE if the current 60 * position is off the end of the text. 61 * @see #getIndex() 62 */ 63 @Override 64 public char current(){ 65 return (char) iterator.current(); 66 } 67 68 /** 69 * Increments the iterator's index by one and returns the character 70 * at the new index. If the resulting index is greater or equal 71 * to getEndIndex(), the current index is reset to getEndIndex() and 72 * a value of DONE is returned. 73 * @return the character at the new position or DONE if the new 74 * position is off the end of the text range. 75 */ 76 @Override 77 public char next(){ 78 //pre-increment 79 iterator.next(); 80 return (char) iterator.current(); 81 } 82 83 /** 84 * Decrements the iterator's index by one and returns the character 85 * at the new index. If the current index is getBeginIndex(), the index 86 * remains at getBeginIndex() and a value of DONE is returned. 87 * @return the character at the new position or DONE if the current 88 * position is equal to getBeginIndex(). 89 */ 90 @Override 91 public char previous(){ 92 //pre-decrement 93 return (char) iterator.previous(); 94 } 95 96 /** 97 * Sets the position to the specified position in the text and returns that 98 * character. 99 * @param position the position within the text. Valid values range from 100 * getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown 101 * if an invalid value is supplied. 102 * @return the character at the specified position or DONE if the specified position is equal to getEndIndex() 103 */ 104 @Override 105 public char setIndex(int position){ 106 iterator.setIndex(position); 107 return (char) iterator.current(); 108 } 109 110 /** 111 * Returns the start index of the text. 112 * @return the index at which the text begins. 113 */ 114 @Override 115 public int getBeginIndex(){ 116 //UCharacterIterator always starts from 0 117 return 0; 118 } 119 120 /** 121 * Returns the end index of the text. This index is the index of the first 122 * character following the end of the text. 123 * @return the index after the last character in the text 124 */ 125 @Override 126 public int getEndIndex(){ 127 return iterator.getLength(); 128 } 129 130 /** 131 * Returns the current index. 132 * @return the current index. 133 */ 134 @Override 135 public int getIndex(){ 136 return iterator.getIndex(); 137 } 138 139 /** 140 * Create a copy of this iterator 141 * @return A copy of this 142 */ 143 @Override 144 public Object clone(){ 145 try { 146 UCharacterIteratorWrapper result = (UCharacterIteratorWrapper) super.clone(); 147 result.iterator = (UCharacterIterator)this.iterator.clone(); 148 return result; 149 } catch (CloneNotSupportedException e) { 150 return null; // only invoked if bad underlying character iterator 151 } 152 } 153 154} 155 156