01: /**
02: *******************************************************************************
03: * Copyright (C) 1996-2004, International Business Machines Corporation and *
04: * others. All Rights Reserved. *
05: *******************************************************************************
06: */package com.ibm.icu.impl;
07:
08: import com.ibm.icu.text.*;
09:
10: /**
11: * @author Doug Felt
12: *
13: */
14:
15: public final class UCharArrayIterator extends UCharacterIterator {
16: private final char[] text;
17: private final int start;
18: private final int limit;
19: private int pos;
20:
21: public UCharArrayIterator(char[] text, int start, int limit) {
22: if (start < 0 || limit > text.length || start > limit) {
23: throw new IllegalArgumentException("start: " + start
24: + " or limit: " + limit + " out of range [0, "
25: + text.length + ")");
26: }
27: this .text = text;
28: this .start = start;
29: this .limit = limit;
30:
31: this .pos = start;
32: }
33:
34: public int current() {
35: return pos < limit ? text[pos] : DONE;
36: }
37:
38: public int getLength() {
39: return limit - start;
40: }
41:
42: public int getIndex() {
43: return pos - start;
44: }
45:
46: public int next() {
47: return pos < limit ? text[pos++] : DONE;
48: }
49:
50: public int previous() {
51: return pos > start ? text[--pos] : DONE;
52: }
53:
54: public void setIndex(int index) {
55: if (index < 0 || index > limit - start) {
56: throw new IndexOutOfBoundsException("index: " + index
57: + " out of range [0, " + (limit - start) + ")");
58: }
59: pos = start + index;
60: }
61:
62: public int getText(char[] fillIn, int offset) {
63: int len = limit - start;
64: System.arraycopy(text, start, fillIn, offset, len);
65: return len;
66: }
67:
68: /**
69: * Creates a copy of this iterator, does not clone the underlying
70: * <code>Replaceable</code>object
71: * @return copy of this iterator
72: */
73: public Object clone() {
74: try {
75: return super .clone();
76: } catch (CloneNotSupportedException e) {
77: return null; // never invoked
78: }
79: }
80: }
|