MCPcopy Index your code
hub / github.com/antirez/botlib / strmatch

Function strmatch

botlib.c:86–204  ·  view source on GitHub ↗

Glob-style pattern matching. Return 1 on match, 0 otherwise. */

Source from the content-addressed store, hash-verified

84
85/* Glob-style pattern matching. Return 1 on match, 0 otherwise. */
86int strmatch(const char *pattern, int patternLen,
87 const char *string, int stringLen, int nocase)
88{
89 while(patternLen && stringLen) {
90 switch(pattern[0]) {
91 case '*':
92 while (patternLen && pattern[1] == '*') {
93 pattern++;
94 patternLen--;
95 }
96 if (patternLen == 1)
97 return 1; /* match */
98 while(stringLen) {
99 if (strmatch(pattern+1, patternLen-1,
100 string, stringLen, nocase))
101 return 1; /* match */
102 string++;
103 stringLen--;
104 }
105 return 0; /* no match */
106 break;
107 case '?':
108 string++;
109 stringLen--;
110 break;
111 case '[':
112 {
113 int not, match;
114
115 pattern++;
116 patternLen--;
117 not = pattern[0] == '^';
118 if (not) {
119 pattern++;
120 patternLen--;
121 }
122 match = 0;
123 while(1) {
124 if (pattern[0] == '\\' && patternLen >= 2) {
125 pattern++;
126 patternLen--;
127 if (pattern[0] == string[0])
128 match = 1;
129 } else if (pattern[0] == ']') {
130 break;
131 } else if (patternLen == 0) {
132 pattern--;
133 patternLen++;
134 break;
135 } else if (patternLen >= 3 && pattern[1] == '-') {
136 int start = pattern[0];
137 int end = pattern[2];
138 int c = string[0];
139 if (start > end) {
140 int t = start;
141 start = end;
142 end = t;
143 }

Callers 1

botProcessUpdatesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected