MCPcopy Create free account
hub / github.com/Singular/Singular / strmatch

Function strmatch

Singular/fehelp.cc:480–560  ·  view source on GitHub ↗

return TRUE if s matches re FALSE, otherwise does not distinguish lower and upper cases inteprets * as wildcard

Source from the content-addressed store, hash-verified

478// does not distinguish lower and upper cases
479// inteprets * as wildcard
480static BOOLEAN strmatch(char* s, char* re)
481{
482 if (s == NULL || *s == '\0')
483 return (re == NULL || *re == '\0' || strcmp(re, "*") == 0);
484 if (re == NULL || *re == '\0') return FALSE;
485
486 int i;
487 char ls[MAX_HE_ENTRY_LENGTH + 1];
488 char rs[MAX_HE_ENTRY_LENGTH + 1];
489 char *l, *r, *ll, *rr;
490
491 // make everything to lower case
492 i=1;
493 ls[0] = '\0';
494 do
495 {
496 if (*s >= 'A' && *s <= 'Z') ls[i] = *s + ('a' - 'A');
497 else ls[i] = *s;
498 i++;
499 s++;
500 } while (*s != '\0');
501 ls[i] = '\0';
502 l = &(ls[1]);
503
504 i=1;
505 rs[0] = '\0';
506 do
507 {
508 if (*re >= 'A' && *re <= 'Z') rs[i]= *re + ('a' - 'A');
509 else rs[i] = *re;
510 i++;
511 re++;
512 } while (*re != '\0');
513 rs[i] = '\0';
514 r = &(rs[1]);
515
516 // chopp of exact matches from beginning and end
517 while (*r != '*' && *r != '\0' && *l != '\0')
518 {
519 if (*r != *l) return FALSE;
520 *r = '\0';
521 *s = '\0';
522 r++;
523 l++;
524 }
525 if (*r == '\0') return (*l == '\0');
526 if (*r == '*' && r[1] == '\0') return TRUE;
527 if (*l == '\0') return FALSE;
528
529 rr = &r[strlen(r) - 1];
530 ll = &l[strlen(l) - 1];
531 while (*rr != '*' && *rr != '\0' && *ll != '\0')
532 {
533 if (*rr != *ll) return FALSE;
534 *rr = '\0';
535 *ll = '\0';
536 rr--;
537 ll--;

Callers 1

heReKey2EntryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected