initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / sql / parser / StringPointer.java
1 package com.quantum.sql.parser;
2
3 public class StringPointer {
4         char[] value;
5         int offset = 0;
6         int mark = 0;
7         public StringPointer(String s) {
8                 value = s.toCharArray();
9         }
10         /**
11          * Returns the next character. Will return 0 if at end of file, but that's not
12          * checkeable because it can be a valid character. You should check with isDone();
13          * @return
14          */
15         public char getNext() {
16                 char retVal = (offset < value.length) ? value[offset] : 0;
17                 offset++;
18                 return retVal;
19         }
20         /**
21          * Returns the next character, without advancing the pointer.
22          *  Will return 0 if at end of file, but that's not
23          * checkeable because it can be a valid character. You should check with isDone();
24          * @return
25          */
26         public char peek() {
27                 char retVal = (offset < value.length) ? value[offset] : 0;
28                 return retVal;
29         }
30         /**
31          * Marks a poing of the stream to come back later (using reset());
32          */
33         public void mark() {
34                 mark = offset;
35         }
36         /**
37          * Returns to a previously marked (with mark()) place.
38          */
39         public void reset() {
40                 offset = mark;
41         }
42         /**
43          * Sets the pointer back a character, in fact 'pop'ing it back to the stream;
44          */
45         public void back() {
46                 if (offset > 0) offset--;
47         }
48         
49         public int getOffset() {
50                 return offset;
51         }
52         /**
53          * @return true if the stream is at an end
54          */
55         public boolean isDone() {
56                 return offset >= value.length;
57         }
58         
59         public int getLength() {
60                 return value.length;
61         }
62 }