Str_Match: fix closure tests for [^] and add unit-test.

This commit is contained in:
Simon J. Gerraty 2017-04-21 22:19:13 +00:00
parent ef3c43b4e3
commit 8b054d3c36
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=317274
3 changed files with 8 additions and 3 deletions

View File

@ -382,8 +382,11 @@ Str_Match(const char *string, const char *pattern)
} else
nomatch = 0;
for (;;) {
if ((*pattern == ']') || (*pattern == 0))
return(nomatch);
if ((*pattern == ']') || (*pattern == 0)) {
if (nomatch)
break;
return(0);
}
if (*pattern == *string)
break;
if (pattern[1] == '-') {
@ -400,7 +403,7 @@ Str_Match(const char *string, const char *pattern)
}
++pattern;
}
if (nomatch)
if (nomatch && (*pattern != ']') && (*pattern != 0))
return 0;
while ((*pattern != ']') && (*pattern != 0))
++pattern;

View File

@ -16,4 +16,5 @@ LIB=e X_LIBS:M*/lib${LIB}.a:tu is "/TMP/LIBE.A"
Mscanner=OK
Upper=One Two Three Four
Lower=five six seven
nose=One Three five
exit status 0

View File

@ -31,3 +31,4 @@ LIST= One Two Three Four five six seven
check-cclass:
@echo Upper=${LIST:M[A-Z]*}
@echo Lower=${LIST:M[^A-Z]*}
@echo nose=${LIST:M[^s]*[ex]}