diff --git a/re.c b/re.c index 20d1474..a356a35 100644 --- a/re.c +++ b/re.c @@ -399,22 +399,7 @@ static int matchone(regex_t p, char c) static int matchstar(regex_t p, regex_t* pattern, const char* text, int* matchlength) { - int prelen = *matchlength; - const char* prepoint = text; - while ((text[0] != '\0') && matchone(p, *text)) - { - text++; - (*matchlength)++; - } - while (text >= prepoint) - { - if (matchpattern(pattern, text--, matchlength)) - return 1; - (*matchlength)--; - } - - *matchlength = prelen; - return 0; + return matchplus(p, pattern, text, matchlength) || matchpattern(pattern, text, matchlength); } static int matchplus(regex_t p, regex_t* pattern, const char* text, int* matchlength) @@ -423,15 +408,14 @@ static int matchplus(regex_t p, regex_t* pattern, const char* text, int* matchle while ((text[0] != '\0') && matchone(p, *text)) { text++; - (*matchlength)++; } - while (text > prepoint) + for (; text > prepoint; text--) { - if (matchpattern(pattern, text--, matchlength)) + if (matchpattern(pattern, text, matchlength)) { + *matchlength += text - prepoint; return 1; - (*matchlength)--; + } } - return 0; }