1 19 package org.netbeans.modules.xml.text.syntax.javacc.lib; 20 21 import java.io.*; 22 23 30 public class StringParserInput extends SimpleCharStream implements CharStream { 31 32 private char[] buffer; 33 34 35 private int pos; 36 37 38 private int begin; 39 40 41 private int len; 42 43 44 private int end; 45 46 public StringParserInput() {} 47 48 49 public void setString(String s) { 50 buffer = s.toCharArray(); 51 begin = pos = 0; 52 len = s.length(); 53 end = len; 54 } 55 56 57 public void setBuffer(char[] buf, int offset, int len) { 58 buffer = buf; 59 begin = pos = offset; 60 this.len = len; 61 end = offset + len; 62 } 63 64 69 public char readChar() throws java.io.IOException { 70 if (pos >= end) 71 throw new java.io.EOFException (); 72 return buffer[pos++]; 73 } 74 75 80 public int getColumn() { 81 return 0; 82 } 83 84 89 public int getLine() { 90 return 0; 91 } 92 93 97 public int getEndColumn() { 98 return 0; 99 } 100 101 105 public int getEndLine() { 106 return 0; 107 } 108 109 113 public int getBeginColumn() { 114 return 0; 115 } 116 117 121 public int getBeginLine() { 122 return 0; 123 } 124 125 131 public void backup(int amount) { 132 if (pos > 1) 133 pos -= amount; 134 } 135 136 141 public char BeginToken() throws java.io.IOException { 142 begin = pos; 143 return readChar (); 144 } 145 146 152 public String GetImage() { 153 return new String (buffer, begin, pos-begin); 154 } 155 156 157 158 public int getLength() { 159 return pos - begin; 160 } 161 162 173 public char[] GetSuffix(int l) { 174 char[] ret = new char[l]; 175 System.arraycopy(buffer, pos - l, ret, 0, l); 176 return ret; 177 } 178 179 185 public void Done() { 186 } 187 188 public String toString() { 189 return "StringParserInput\n Pos:" + pos + " len:" + len + " #################\n" + buffer; } 191 } 192 | Popular Tags |