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