From 7b870faf3a18782094a7e75d8f4ac118fde40be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 31 Dec 2013 15:57:20 +0000 Subject: [PATCH] [INTERPRETER] * BUG: Fix LIKE operator when the {...} syntax is not at the end of the pattern. git-svn-id: svn://localhost/gambas/trunk@6042 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- main/gbx/gbx_regexp.c | 81 ++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/main/gbx/gbx_regexp.c b/main/gbx/gbx_regexp.c index 28eb5b5da..5e4136f47 100644 --- a/main/gbx/gbx_regexp.c +++ b/main/gbx/gbx_regexp.c @@ -184,6 +184,8 @@ bool REGEXP_match(const char *pattern, int len_pattern, const char *string, int { const char *save_string; int save_len_string; + const char *save_pattern; + int save_len_pattern; string--; len_string++; save_string = string; @@ -191,51 +193,58 @@ bool REGEXP_match(const char *pattern, int len_pattern, const char *string, int for(;;) { - if (len_pattern == 0) - THROW(E_REGEXP, "Missing '}'"); - - if (len_string == 0) - break; - - _next_pattern(); - - if (cp == '}') - return FALSE; - - if (cp == ',') - goto NEXT_ELEMENT; - - if (len_string == 0) - return FALSE; - - _next_string(); - - if (tolower(cp) == tolower(cs)) - continue; - for(;;) { - _next_pattern(); - if (cp == '}') - return FALSE; - if (cp == ',' || len_pattern == 0) + if (len_pattern == 0) + THROW(E_REGEXP, "Missing '}'"); + + if (len_string == 0) break; + + _next_pattern(); + + if (cp == '}' || cp == ',') + break; + + _next_string(); + + if (tolower(cp) == tolower(cs)) + continue; + + for(;;) + { + _next_pattern(); + if (cp == '}') + return FALSE; + if (cp == ',' || len_pattern == 0) + break; + } + + string = save_string; + len_string = save_len_string; } - NEXT_ELEMENT: + if (len_pattern == 0) + return (len_string == 0); + save_pattern = pattern; + save_len_pattern = len_pattern; + + while (cp != '}') + { + if (len_pattern == 0) + THROW(E_REGEXP, "Missing '}'"); + _next_pattern(); + } + + if (REGEXP_match(pattern, len_pattern, string, len_string)) + return TRUE; + + pattern = save_pattern; + len_pattern = save_len_pattern; string = save_string; len_string = save_len_string; } - - while (cp != '}') - { - if (len_pattern == 0) - THROW(E_REGEXP, "Missing '}'"); - _next_pattern(); - } - - continue; } if (cp == '\\')