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
20 /** Return the position in the string pointed to */
\r
26 /** This contains the escape character, which is \ by default. */
\r
27 public char esc = Pattern.ESC;
\r
29 /** Returns the current, possibly escaped, character. */
\r
30 public char thisChar()
\r
35 boolean dontMatch, eos;
\r
37 /** tell whether we are at end of string */
\r
38 public boolean eos()
\r
43 /** initialize a StrPos from another StrPos. */
\r
44 public StrPos(StrPos sp)
\r
49 /** copy a StrPos from sp to this. */
\r
50 public void dup(StrPos sp)
\r
55 dontMatch = sp.dontMatch;
\r
59 /** Initialize a StrPos by giving it a String, and a
\r
60 position within the String. */
\r
61 public StrPos(String s, int pos)
\r
68 /** Advance the place where StrPos points within the String.
\r
69 Counts a backslash as part of the next character. */
\r
73 if (pos >= s.length())
\r
80 if (c == esc && pos + 1 < s.length())
\r
100 /** Compare the (possibly escaped) character
\r
101 pointed to by StrPos. Return true if they are the
\r
102 same, but lways return if character pointed to is escaped. */
\r
103 public boolean match(char ch)
\r
105 if (dontMatch || eos)
\r
112 /** As match, but only matches if the character is escaped. */
\r
113 public boolean escMatch(char ch)
\r
115 if (!dontMatch || eos)
\r
122 /** Returns true if the current
\r
123 character is escaped (preceeded by "\"). */
\r
124 public boolean escaped()
\r
129 /** Increment the string pointer by each character in
\r
130 <pre>st</pre> that matches a non-escaped
\r
132 public boolean incMatch(String st)
\r
134 StrPos sp = new StrPos(this);
\r
136 for (i = 0; i < st.length(); i++)
\r
138 if (!sp.match(st.charAt(i)))
\r
148 /** Read in an integer. */
\r
149 public patInt getPatInt()
\r
151 if (incMatch("inf"))
\r
153 return new patInf();
\r
156 StrPos sp = new StrPos(this);
\r
157 for (i = 0; !sp.eos && sp.c >= '0' && sp.c <= '9'; i++)
\r
159 cnt = 10 * cnt + sp.c - '0';
\r
167 return new patInt(cnt);
\r
170 /** get the string that we are processing. */
\r
171 public String getString()
\r