1 28 29 package com.caucho.util; 30 31 import java.text.CharacterIterator ; 32 33 36 public abstract class CharCursor implements CharacterIterator { 37 40 public abstract int getIndex(); 41 42 public abstract int getBeginIndex(); 43 public abstract int getEndIndex(); 44 47 public abstract char setIndex(int pos); 48 49 public abstract char next(); 50 51 public abstract char previous(); 52 53 public abstract char current(); 54 55 public abstract Object clone(); 56 57 public char first() 58 { 59 return setIndex(getBeginIndex()); 60 } 61 public char last() 62 { 63 return setIndex(getEndIndex()); 64 } 65 66 69 public char read() 70 { 71 char value = current(); 72 next(); 73 return value; 74 } 75 76 public char prev() 77 { 78 int pos = getIndex(); 79 char value = previous(); 80 setIndex(pos); 81 return value; 82 } 83 84 87 public char skip(int n) 88 { 89 for (int i = 0; i < n; i++) 90 next(); 91 return current(); 92 } 93 94 public void subseq(CharBuffer cb, int begin, int end) 95 { 96 int pos = getIndex(); 97 98 char ch = setIndex(begin); 99 for (int i = begin; i < end; i++) { 100 if (ch != DONE) 101 cb.append(ch); 102 ch = next(); 103 } 104 105 setIndex(pos); 106 } 107 108 public void subseq(CharBuffer cb, int length) 109 { 110 char ch = current(); 111 for (int i = 0; i < length; i++) { 112 if (ch != DONE) 113 cb.append(ch); 114 ch = next(); 115 } 116 } 117 118 123 public boolean regionMatches(char []cb, int offset, int length) 124 { 125 int pos = getIndex(); 126 127 char ch = current(); 128 for (int i = 0; i < length; i++) { 129 if (cb[i + offset] != ch) { 130 setIndex(pos); 131 return false; 132 } 133 ch = next(); 134 } 135 136 return true; 137 } 138 139 144 public boolean regionMatchesIgnoreCase(char []cb, int offset, int length) 145 { 146 int pos = getIndex(); 147 148 char ch = current(); 149 for (int i = 0; i < length; i++) { 150 if (ch == DONE) { 151 setIndex(pos); 152 return false; 153 } 154 155 if (Character.toLowerCase(cb[i + offset]) != Character.toLowerCase(ch)) { 156 setIndex(pos); 157 return false; 158 } 159 160 ch = next(); 161 } 162 163 return true; 164 } 165 } 166 | Popular Tags |