2 * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
\r
4 * The program is provided "as is" without any warranty express or
\r
5 * implied, including the warranty of non-infringement and the implied
\r
6 * warranties of merchantibility and fitness for a particular purpose.
\r
7 * IBM will not be liable for any damages suffered by you as a result
\r
8 * of using the Program. In no event will IBM be liable for any
\r
9 * special, indirect or consequential damages or lost profits even if
\r
10 * IBM has been advised of the possibility of their occurrence. IBM
\r
11 * will not be liable for any third party claims against you.
\r
13 package com.ibm.richtext.styledtext;
\r
15 import java.text.CharacterIterator;
\r
17 final class CharBufferIterator implements CharacterIterator,
\r
20 static final String COPYRIGHT =
\r
21 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
\r
22 private int fRangeStart;
\r
23 private int fRangeLimit;
\r
24 private int fCurrentIndex;
\r
25 private char fStorage[];
\r
27 private int fGapLength;
\r
28 private Validation fValidation;
\r
30 CharBufferIterator(int start,
\r
35 Validation validation) {
\r
37 if (start > limit) {
\r
38 throw new IllegalArgumentException("start > limit");
\r
40 fRangeStart = start;
\r
41 fRangeLimit = limit;
\r
42 fCurrentIndex = fRangeStart;
\r
45 fGapLength = (storage==null? 0 : storage.length) - length;
\r
46 fValidation = validation;
\r
49 private void checkValidation() {
\r
51 if (!fValidation.isValid()) {
\r
52 throw new Error("Iterator is no longer valid");
\r
58 return setIndex(fRangeStart);
\r
63 return setIndex(fRangeLimit - 1);
\r
66 public char current()
\r
69 if (fCurrentIndex < fRangeStart || fCurrentIndex >= fRangeLimit)
\r
71 int i = (fCurrentIndex < fGap) ? fCurrentIndex : (fCurrentIndex + fGapLength);
\r
79 if (fCurrentIndex >= fRangeLimit)
\r
81 fCurrentIndex = fRangeLimit;
\r
84 int i = (fCurrentIndex < fGap) ? fCurrentIndex : (fCurrentIndex + fGapLength);
\r
88 public char previous()
\r
91 if (fCurrentIndex >= fRangeStart)
\r
93 fCurrentIndex = fRangeStart;
\r
97 public char setIndex(int i)
\r
99 if (i < fRangeStart || i > fRangeLimit)
\r
100 throw new IllegalArgumentException("Invalid position");
\r
105 public int getBeginIndex()
\r
107 return fRangeStart;
\r
110 public int getEndIndex()
\r
112 return fRangeLimit;
\r
115 public int getIndex()
\r
117 return fCurrentIndex;
\r
120 public Object clone()
\r
123 return super.clone();
\r
125 catch (CloneNotSupportedException e) {
\r