changeset 638:c4bca120bfb0

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Jan 2020 12:23:59 +0200
parents 8e6caddfe117
children 8c957ad9d4c3
files th_regex.c
diffstat 1 files changed, 20 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/th_regex.c	Tue Jan 21 08:07:52 2020 +0200
+++ b/th_regex.c	Tue Jan 21 12:23:59 2020 +0200
@@ -385,6 +385,8 @@
                     goto exit;
                 }
 
+                // XXX TODO Parse/support ranges [0-9a-zA-Z_-]
+
                 th_regex_node_init(&node);
                 node.type = (ctx.pattern[start] == '^') ?
                     TH_RE_TYPE_LIST_REVERSE : TH_RE_TYPE_LIST;
@@ -443,8 +445,6 @@
 }
 
 
-
-
 void th_regex_free(th_regex_ctx *expr)
 {
     if (expr != NULL)
@@ -463,7 +463,8 @@
             switch (node->type)
             {
                 case TH_RE_TYPE_SUBEXPR:
-                    DBG_RE_FREE("  SUBEXPR: %p vs %p\n", (void *) expr, (void *) node->match.expr);
+                    DBG_RE_FREE("  SUBEXPR: %p vs %p\n",
+                        (void *) expr, (void *) node->match.expr);
                     th_regex_free(node->match.expr);
                     break;
 
@@ -498,67 +499,63 @@
     size_t *offs, const th_regex_node *node, const int flags)
 {
     th_regex_char cch;
-    BOOL ret = FALSE;
+    BOOL res = FALSE;
 
-    DBG_RE_MATCH("    node_START [%s]: '%s': ", re_match_types[node->type], haystack + *offs);
+    DBG_RE_MATCH("    node_START [%s]: '%s': ",
+        re_match_types[node->type], haystack + *offs);
 
     switch (node->type)
     {
         case TH_RE_TYPE_SUBEXPR:
             DBG_RE_MATCH("subexpr ..\n");
-            ret = th_regex_do_match_expr(node->match.expr, haystack, offs, flags);
+            res = th_regex_do_match_expr(node->match.expr, haystack, offs, flags);
+            return res;
             break;
 
         case TH_RE_TYPE_LIST:
         case TH_RE_TYPE_LIST_REVERSE:
-            DBG_RE_MATCH("[%s]\n", node->match.list.chars);
-            ret = FALSE;
+            DBG_RE_MATCH("[%s]", node->match.list.chars);
             if ((cch = haystack[*offs]) == 0)
                 goto out;
 
             // Could be optimized, perhaps .. sort match.chars, binary search etc?
-            // XXX TODO Ranges and escapes are not supported yet
+            // XXX TODO Ranges are not supported yet
             for (size_t n = 0; n < node->match.list.nchars; n++)
             if (node->match.list.chars[n] == cch)
             {
-                ret = TRUE;
+                res = TRUE;
                 break;
             }
 
             if (node->type == TH_RE_TYPE_LIST_REVERSE)
-                ret = !ret;
+                res = !res;
 
             (*offs)++;
             break;
 
         case TH_RE_TYPE_ANY_CHAR:
-            DBG_RE_MATCH("\n");
             if ((cch = haystack[*offs]) == 0)
-            {
-                ret = FALSE;
                 goto out;
-            }
 
-            ret = TRUE;
+            res = TRUE;
             (*offs)++;
             break;
 
         case TH_RE_TYPE_CHAR:
-            DBG_RE_MATCH("'%c'\n", node->match.chr);
+            DBG_RE_MATCH("'%c'", node->match.chr);
             if ((cch = haystack[*offs]) == 0)
-            {
-                ret = FALSE;
                 goto out;
-            }
 
-            ret = (cch == node->match.chr);
+            res = (cch == node->match.chr);
             (*offs)++;
             break;
     }
 
 out:
-    DBG_RE_MATCH("    node_DONE  [%s]: match %s\n", re_match_types[node->type], ret ? "YES" : "NO");
-    return ret;
+    DBG_RE_MATCH(", match=%s\n",
+        res ? "YES" : "NO");
+
+    return res;
 }