Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * returns a <code>TextStore</code> which contains submatches, if any, pertaining to the most
  * recent match. The object returned should be treated read-only. Its contents are only valid
  * until the next match operation.
  *
  * @throws IllegalStateException if the most recent application of <code>this</code> did not yield
  *     a match.
  */
 public TextStore submatches() {
   if (a == null || a == DfaRun.EOF) {
     throw new IllegalStateException("no recent match available");
   }
   if (!analyzed) {
     analyzed = true;
     ts.clear();
     ts.appendPart(out, 0, out.length());
     smd.analyze(ts, a);
   }
   return ts;
 }
Esempio n. 3
0
 /**
  * checks if the whole input sequence starting at position <code>pos</code> can be matched.
  *
  * @return <code>true</code> iff the whole input sequence starting at position <code>pos</code>
  *     and ending at <code>s.length()</code> can be matched.
  */
 public boolean matches(CharSequence s, int pos) {
   return atStartOf(s, pos) != -1 && out.length() == s.length() - pos;
 }
Esempio n. 4
0
 /**
  * returns the number of characters matched by the most recent match call to any of <code>matches
  * </code>, <code>atStartOf</code> or <code>find</code>.
  *
  * @throws IllegalStateException if the most recent application of <code>this</code> did not yield
  *     a match.
  */
 public int length() {
   if (a == null || a == DfaRun.EOF) {
     throw new IllegalStateException("no recent match available");
   }
   return out.length();
 }