src/com/sun/org/apache/regexp/internal/CharacterArrayCharacterIterator.java

changeset 2116
aaee9ae4799a
parent 759
7ea027fae4d8
equal deleted inserted replaced
2090:3b8ebb957957 2116:aaee9ae4799a
1 /*
2 * reserved comment block
3 * DO NOT REMOVE OR ALTER!
4 */
5 /*
6 * Copyright 1999-2004 The Apache Software Foundation.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21 package com.sun.org.apache.regexp.internal;
22
23 /**
24 * Encapsulates char[] as CharacterIterator
25 *
26 * @author <a href="mailto:ales.novak@netbeans.com">Ales Novak</a>
27 */
28 public final class CharacterArrayCharacterIterator implements CharacterIterator
29 {
30 /** encapsulated */
31 private final char[] src;
32 /** offset in the char array */
33 private final int off;
34 /** used portion of the array */
35 private final int len;
36
37 /** @param src - encapsulated String */
38 public CharacterArrayCharacterIterator(char[] src, int off, int len)
39 {
40 this.src = src;
41 this.off = off;
42 this.len = len;
43 }
44
45 /** @return a substring */
46 public String substring(int beginIndex, int endIndex)
47 {
48 if (endIndex > len) {
49 throw new IndexOutOfBoundsException("endIndex=" + endIndex
50 + "; sequence size=" + len);
51 }
52 if (beginIndex < 0 || beginIndex > endIndex) {
53 throw new IndexOutOfBoundsException("beginIndex=" + beginIndex
54 + "; endIndex=" + endIndex);
55 }
56 return new String(src, off + beginIndex, endIndex - beginIndex);
57 }
58
59 /** @return a substring */
60 public String substring(int beginIndex)
61 {
62 return substring(beginIndex, len);
63 }
64
65 /** @return a character at the specified position. */
66 public char charAt(int pos)
67 {
68 return src[off + pos];
69 }
70
71 /** @return <tt>true</tt> iff if the specified index is after the end of the character stream */
72 public boolean isEnd(int pos)
73 {
74 return (pos >= len);
75 }
76 }

mercurial