Ejemplo 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;
 }
 /** ***************************************************************** */
 public static void test_Oflow()
     throws ReSyntaxException, CompileDfaException, java.io.IOException {
   StringBuffer s = new StringBuffer();
   for (int i = 0; i < 256; i++) s.append("(!a)x");
   Exception e = null;
   try {
     Nfa nfa = new Nfa(s, Copy.COPY);
   } catch (ReSyntaxException _e) {
     // we want this to happen
     e = _e;
   }
   assertTrue(e instanceof ReSyntaxException);
   assertTrue(e.toString().startsWith("ReSyntaxException: too many"));
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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();
 }