MCPcopy Create free account
hub / github.com/F-Stack/f-stack / stringmatchlen

Function stringmatchlen

app/redis-6.2.6/src/util.c:48–166  ·  view source on GitHub ↗

Glob-style pattern matching. */

Source from the content-addressed store, hash-verified

46
47/* Glob-style pattern matching. */
48int stringmatchlen(const char *pattern, int patternLen,
49 const char *string, int stringLen, int nocase)
50{
51 while(patternLen && stringLen) {
52 switch(pattern[0]) {
53 case '*':
54 while (patternLen && pattern[1] == '*') {
55 pattern++;
56 patternLen--;
57 }
58 if (patternLen == 1)
59 return 1; /* match */
60 while(stringLen) {
61 if (stringmatchlen(pattern+1, patternLen-1,
62 string, stringLen, nocase))
63 return 1; /* match */
64 string++;
65 stringLen--;
66 }
67 return 0; /* no match */
68 break;
69 case '?':
70 string++;
71 stringLen--;
72 break;
73 case '[':
74 {
75 int not, match;
76
77 pattern++;
78 patternLen--;
79 not = pattern[0] == '^';
80 if (not) {
81 pattern++;
82 patternLen--;
83 }
84 match = 0;
85 while(1) {
86 if (pattern[0] == '\\' && patternLen >= 2) {
87 pattern++;
88 patternLen--;
89 if (pattern[0] == string[0])
90 match = 1;
91 } else if (pattern[0] == ']') {
92 break;
93 } else if (patternLen == 0) {
94 pattern--;
95 patternLen++;
96 break;
97 } else if (patternLen >= 3 && pattern[1] == '-') {
98 int start = pattern[0];
99 int end = pattern[2];
100 int c = string[0];
101 if (start > end) {
102 int t = start;
103 start = end;
104 end = t;
105 }

Callers 8

pubsubPublishMessageFunction · 0.85
pubsubCommandFunction · 0.85
keysCommandFunction · 0.85
scanGenericCommandFunction · 0.85
ACLCheckCommandPermFunction · 0.85
stringmatchFunction · 0.85
stringmatchlen_fuzz_testFunction · 0.85

Calls 1

tolowerFunction · 0.85

Tested by

no test coverage detected