2 // This software is now distributed according to
3 // the Lesser Gnu Public License. Please see
4 // http://www.gnu.org/copyleft/lesser.txt for
8 package com.stevesoft.pat;
11 Shareware: package pat
12 <a href="copyright.html">Copyright 2001, Steven R. Brandt</a>
15 * StrPos is used internally by regex to parse the regular expression.
23 /** Return the position in the string pointed to */
29 /** This contains the escape character, which is \ by default. */
30 public char esc = Pattern.ESC;
34 /** Returns the current, possibly escaped, character. */
35 public char thisChar()
40 boolean dontMatch, eos;
42 /** tell whether we are at end of string */
48 /** initialize a StrPos from another StrPos. */
49 public StrPos(StrPos sp)
54 /** copy a StrPos from sp to this. */
55 public void dup(StrPos sp)
60 dontMatch = sp.dontMatch;
65 * Initialize a StrPos by giving it a String, and a position within the
68 public StrPos(String s, int pos)
76 * Advance the place where StrPos points within the String. Counts a backslash
77 * as part of the next character.
82 if (pos >= s.length())
89 if (c == esc && pos + 1 < s.length())
110 * Compare the (possibly escaped) character pointed to by StrPos. Return true
111 * if they are the same, but lways return if character pointed to is escaped.
113 public boolean match(char ch)
115 if (dontMatch || eos)
122 /** As match, but only matches if the character is escaped. */
123 public boolean escMatch(char ch)
125 if (!dontMatch || eos)
133 * Returns true if the current character is escaped (preceeded by "\").
135 public boolean escaped()
141 * Increment the string pointer by each character in
147 * that matches a non-escaped character.
149 public boolean incMatch(String st)
151 StrPos sp = new StrPos(this);
153 for (i = 0; i < st.length(); i++)
155 if (!sp.match(st.charAt(i)))
165 /** Read in an integer. */
166 public patInt getPatInt()
173 StrPos sp = new StrPos(this);
174 for (i = 0; !sp.eos && sp.c >= '0' && sp.c <= '9'; i++)
176 cnt = 10 * cnt + sp.c - '0';
184 return new patInt(cnt);
187 /** get the string that we are processing. */
188 public String getString()