예제 #1
0
 /**
  * tests whether <code>this</code> matches a prefix of <code>s</code> starting at position <code>
  * pos</code>.
  *
  * @return the length of the match or -1.
  */
 public int atStartOf(CharSequence s, int pos) {
   analyzed = false;
   in.setSource(s, pos);
   out.setLength(0);
   try {
     a = dfa.match(in, out, smd);
   } catch (java.io.IOException e) {
     throw new Error("impossible", e);
   }
   return (a != null && a != DfaRun.EOF) ? out.length() : -1;
 }
예제 #2
0
 /**
  * tries to find <code>this</code> in <code>s</code> starting at position <code>start</code>.
  *
  * @return the position of the match within <code>s</code>, i.e. <b>not</b> relative to <code>
  *     start</code>. If not match can be found, -1 is returned.
  */
 public int find(CharSequence s, int start) {
   analyzed = false;
   in.setSource(s, start);
   out.setLength(0);
   int l = s.length();
   while (start < l) {
     try {
       a = dfa.match(in, out, smd);
     } catch (java.io.IOException e) {
       throw new Error("impossible", e);
     }
     if (a != null && a != DfaRun.EOF) return start;
     start += 1;
     in.read();
   }
   return -1;
 }