X-Git-Url: http://git.phpeclipse.com diff --git a/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/StringPointer.java b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/StringPointer.java new file mode 100644 index 0000000..846da29 --- /dev/null +++ b/archive/net.sourceforge.phpeclipse.quantum.sql/src/com/quantum/sql/parser/StringPointer.java @@ -0,0 +1,62 @@ +package com.quantum.sql.parser; + +public class StringPointer { + char[] value; + int offset = 0; + int mark = 0; + public StringPointer(String s) { + value = s.toCharArray(); + } + /** + * Returns the next character. Will return 0 if at end of file, but that's not + * checkeable because it can be a valid character. You should check with isDone(); + * @return + */ + public char getNext() { + char retVal = (offset < value.length) ? value[offset] : 0; + offset++; + return retVal; + } + /** + * Returns the next character, without advancing the pointer. + * Will return 0 if at end of file, but that's not + * checkeable because it can be a valid character. You should check with isDone(); + * @return + */ + public char peek() { + char retVal = (offset < value.length) ? value[offset] : 0; + return retVal; + } + /** + * Marks a poing of the stream to come back later (using reset()); + */ + public void mark() { + mark = offset; + } + /** + * Returns to a previously marked (with mark()) place. + */ + public void reset() { + offset = mark; + } + /** + * Sets the pointer back a character, in fact 'pop'ing it back to the stream; + */ + public void back() { + if (offset > 0) offset--; + } + + public int getOffset() { + return offset; + } + /** + * @return true if the stream is at an end + */ + public boolean isDone() { + return offset >= value.length; + } + + public int getLength() { + return value.length; + } +}