1 28 29 package com.caucho.util; 30 31 34 public class StringCharCursor extends CharCursor { 35 String string; 36 int pos; 37 38 public StringCharCursor(String string) 39 { 40 this.string = string; 41 this.pos = 0; 42 } 43 44 public StringCharCursor(String string, int offset) 45 { 46 this.string = string; 47 this.pos = offset; 48 } 49 50 53 public int getIndex() { return pos; } 54 55 public int getBeginIndex() { return 0; } 56 public int getEndIndex() { return string.length(); } 57 60 public char setIndex(int pos) 61 { 62 if (pos < 0) { 63 this.pos = 0; 64 return DONE; 65 } 66 else if (pos >= string.length()) { 67 this.pos = string.length(); 68 return DONE; 69 } 70 else { 71 this.pos = pos; 72 return string.charAt(pos); 73 } 74 } 75 76 81 public char next() 82 { 83 if (++pos >= string.length()) { 84 pos = string.length(); 85 return DONE; 86 } 87 else 88 return string.charAt(pos); 89 } 90 91 96 public char previous() 97 { 98 if (--pos < 0) { 99 pos = 0; 100 return DONE; 101 } 102 else 103 return string.charAt(pos); 104 } 105 106 public char current() 107 { 108 if (pos >= string.length()) 109 return DONE; 110 else 111 return string.charAt(pos); 112 } 113 114 117 public char skip(int n) 118 { 119 pos += n; 120 if (pos >= string.length()) { 121 pos = string.length(); 122 return DONE; 123 } else 124 return string.charAt(pos); 125 } 126 127 public void init(String string) 128 { 129 this.string = string; 130 this.pos = 0; 131 } 132 133 public Object clone() 134 { 135 return new StringCharCursor(string); 136 } 137 } 138 | Popular Tags |