Menu

#1 coordinate of the matched pattern

open
nobody
None
2
2005-12-30
2005-12-30
No

I know you are working on 'Named Groups', but i wanted
to display how i managed to retrieve coordinates of the
matched pattern with your current implementation. Your
implementation has catched my eye becouse it works
seamless on streams, which is very useful for the
linked string buffer i'm implementing (string
concatenation is generally much faster without the
realloc overhead).
Attached is the the LinkedStringBuffer utilizing the
new method.

8<--------------------------------------------->8

--- Pattern.java.original 2003-02-21 12:25:48.000000000
+0300
+++ Pattern.java 2005-12-30 18:59:28.313595200 +0300
@@ -202,6 +202,23 @@
return ((Automaton_Pattern.PState)state).isFinal;
}

+ public int containsEnd(char[] chars,int offset,int
length) {
+ Automaton.State state =
((Automaton_Pattern)this.automaton).getStartState();
+ if (state==null) return -1;
+
+ loop: for (;length>0; ++offset, --length) {
+ for (Automaton.State.Transition
trans=state.transitions; trans!=null; trans=trans.next) {
+ if (trans.charSet.contains(chars[offset])) {
+ state = trans.toState;
+ continue loop;
+ }
+ }
+ return ((Automaton_Pattern.PState)state).isFinal
? offset : -1;
+ }
+
+ return ((Automaton_Pattern.PState)state).isFinal ?
offset : -1;
+ }
+
public boolean contains(java.io.Reader in) throws
java.io.IOException {
Automaton.State state =
((Automaton_Pattern)this.automaton).getStartState();
if (state==null) return false;

Discussion

  • Artem Grinblat

    Artem Grinblat - 2005-12-30
     
  • Artem Grinblat

    Artem Grinblat - 2005-12-30

    the patch

     
  • Artem Grinblat

    Artem Grinblat - 2005-12-30
    • priority: 5 --> 2
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.