]> git.xolatile.top Git - public-libhl.git/commitdiff
regex lenghts work
authoranon <anon@anon.anon>
Sat, 26 Aug 2023 20:39:07 +0000 (22:39 +0200)
committeranon <anon@anon.anon>
Sat, 26 Aug 2023 20:39:07 +0000 (22:39 +0200)
source/hl.h
source/regex.c
source/regex.h

index a46080b50630f05b3c3b707f1ee188087cc3805b..d927075cf16b4bfa9512263f8958a62de30489c7 100644 (file)
@@ -187,9 +187,10 @@ int token_fits(const token_t * const       token,
                const char    * const       to,
                const int                   string_offset,
                                 int     *             match_offset) {
+       UNUSED(match_offset);
 
        //return regex_match(pattern, to, string_offset, match_offset);
-       return regex_search(token->syntax, to + string_offset);
+       return regex_match(token->syntax, to + string_offset);
 }
 
 void render_string(const char * const string,
index 6dea9eb93795f3330ca8eed763cfe3e4cfdd492c..876a296d8ca6ae4770e463be1a2d5afa6fad10ad 100644 (file)
@@ -458,7 +458,7 @@ static bool catch_(const regex_t * const regex,
 static int regex_assert(const regex_t * const  regex,
                          const char    * const string,
                                int              state,
-                                                          int     *        width) {
+                                                          int              width) {
 
        for (const char * s = string; *s != '\00'; s++) {
                // delta
@@ -466,8 +466,9 @@ static int regex_assert(const regex_t * const  regex,
                        const delta_t * const delta = *(delta_t**)vector_get(&regex->delta_table, i);
                        if ((delta->in == state) 
                        &&  (delta->input == *s)) {
-                               if(regex_assert(regex, s + delta->width, delta->to)){
-                                       return true;
+                               int r = regex_assert(regex, s + delta->width, delta->to, width + 1);
+                               if(r){
+                                       return r;
                                }
                        }
                }
@@ -476,7 +477,7 @@ static int regex_assert(const regex_t * const  regex,
                        continue;
                }
 
-               return (state == regex->accepting_state);
+               return (state == regex->accepting_state) ? width : false;
        }
 
        return false;
@@ -492,13 +493,12 @@ int regex_match(      regex_t *        regex,
                return true;
        }
 
-       int r = 0;
-       return regex_assert(regex, string, 0, &r);
+       return regex_assert(regex, string, 0, 0);
 }
 
 bool regex_search(      regex_t *        regex,
                   const char    * const string) {
 
-       return (bool)regex_match(regex, string, 0);
+       return (bool)regex_match(regex, string);
 }
 
index 52d1b121bbdff916870041c78e3c28afdb1ade76..0049fcc08cd0e74b32d70db3dffa4fa7601003c4 100644 (file)
@@ -14,8 +14,9 @@ typedef struct {
 } regex_t;
 
 extern regex_t * regex_compile(const char * const pattern);
-extern bool regex_search(regex_t * regex, const char * const string);
 extern int       regex_free(regex_t * const regex);
+extern bool      regex_search(regex_t * regex, const char * const string);
+extern int       regex_match(regex_t * regex, const char * const string);
 
 extern bool is_magic(const char c);