• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
11 package ohos.global.icu.impl;
12 
13 import ohos.global.icu.text.UCharacterIterator;
14 
15 
16 /**
17  * @author Doug Felt
18  * @hide exposed on OHOS
19  *
20  */
21 
22 public final class UCharArrayIterator extends UCharacterIterator {
23     private final char[] text;
24     private final int start;
25     private final int limit;
26     private int pos;
27 
UCharArrayIterator(char[] text, int start, int limit)28     public UCharArrayIterator(char[] text, int start, int limit) {
29         if (start < 0 || limit > text.length || start > limit) {
30             throw new IllegalArgumentException("start: " + start + " or limit: "
31                                                + limit + " out of range [0, "
32                                                + text.length + ")");
33         }
34         this.text = text;
35         this.start = start;
36         this.limit = limit;
37 
38         this.pos = start;
39     }
40 
41     @Override
current()42     public int current() {
43         return pos < limit ? text[pos] : DONE;
44     }
45 
46     @Override
getLength()47     public int getLength() {
48         return limit - start;
49     }
50 
51     @Override
getIndex()52     public int getIndex() {
53         return pos - start;
54     }
55 
56     @Override
next()57     public int next() {
58         return pos < limit ? text[pos++] : DONE;
59     }
60 
61     @Override
previous()62     public int previous() {
63         return pos > start ? text[--pos] : DONE;
64     }
65 
66     @Override
setIndex(int index)67     public void setIndex(int index) {
68         if (index < 0 || index > limit - start) {
69             throw new IndexOutOfBoundsException("index: " + index +
70                                                 " out of range [0, "
71                                                 + (limit - start) + ")");
72         }
73         pos = start + index;
74     }
75 
76     @Override
getText(char[] fillIn, int offset)77     public int getText(char[] fillIn, int offset) {
78         int len = limit - start;
79         System.arraycopy(text, start, fillIn, offset, len);
80         return len;
81     }
82 
83     /**
84      * Creates a copy of this iterator, does not clone the underlying
85      * <code>Replaceable</code>object
86      * @return copy of this iterator
87      */
88     @Override
clone()89     public Object clone(){
90         try {
91           return super.clone();
92         } catch (CloneNotSupportedException e) {
93             return null; // never invoked
94         }
95     }
96 }