File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -36,9 +36,7 @@ bool isMatch(const char *s, const char *p) {
3636 bool star = false ;
3737 const char *s1, *p1;
3838 while ( *s && (*p || star) ){
39- if (*p==' ?' || *s == *p){
40- s++; p++;
41- }else if (*p==' *' ){
39+ if (*p==' *' ){
4240 // skip the "*", and mark a flag
4341 star = true ;
4442 p++;
@@ -47,6 +45,8 @@ bool isMatch(const char *s, const char *p) {
4745 // use s1 and p1 to store where the "*" match starts.
4846 s1 = s;
4947 p1 = p;
48+ }else if (*p==' ?' || *s == *p){
49+ s++; p++;
5050 }else {
5151 if (star==false ) return false ;
5252 // if meet "*" previously, but the *s != *p
@@ -89,6 +89,12 @@ int main(int argc, char** argv)
8989 s = " a" ;
9090 p = " a**" ;
9191 cout << s << " , " << p << " : " << isMatch (s, p) << endl;
92+
93+ /* thanks @jakwings (GitHub) find this problem */
94+ s = " *aa" ; // <-- it is not a pattern, it just a string where '*' is not a wildcard
95+ p = " *a" ;
96+ cout << s << " , " << p << " : " << isMatch (s, p) << endl;
97+
9298 if (argc>2 ){
9399 s = argv[1 ];
94100 p = argv[2 ];
You can’t perform that action at this time.
0 commit comments