aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lstrlib.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 5462222a..88f61547 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.68 2001/03/26 14:31:49 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.69 2001/07/17 18:46:49 roberto Exp $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -181,26 +181,26 @@ static const l_char *luaI_classend (MatchState *ms, const l_char *p) {
181} 181}
182 182
183 183
184static int match_class (l_char c, l_char cl) { 184static int match_class (l_charint c, l_charint cl) {
185 int res; 185 int res;
186 switch (tolower(uchar(cl))) { 186 switch (tolower(cl)) {
187 case l_c('a') : res = isalpha(uchar(c)); break; 187 case l_c('a') : res = isalpha(c); break;
188 case l_c('c') : res = iscntrl(uchar(c)); break; 188 case l_c('c') : res = iscntrl(c); break;
189 case l_c('d') : res = isdigit(uchar(c)); break; 189 case l_c('d') : res = isdigit(c); break;
190 case l_c('l') : res = islower(uchar(c)); break; 190 case l_c('l') : res = islower(c); break;
191 case l_c('p') : res = ispunct(uchar(c)); break; 191 case l_c('p') : res = ispunct(c); break;
192 case l_c('s') : res = isspace(uchar(c)); break; 192 case l_c('s') : res = isspace(c); break;
193 case l_c('u') : res = isupper(uchar(c)); break; 193 case l_c('u') : res = isupper(c); break;
194 case l_c('w') : res = isalnum(uchar(c)); break; 194 case l_c('w') : res = isalnum(c); break;
195 case l_c('x') : res = isxdigit(uchar(c)); break; 195 case l_c('x') : res = isxdigit(c); break;
196 case l_c('z') : res = (c == l_c('\0')); break; 196 case l_c('z') : res = (c == 0); break;
197 default: return (cl == c); 197 default: return (cl == c);
198 } 198 }
199 return (islower(uchar(cl)) ? res : !res); 199 return (islower(cl) ? res : !res);
200} 200}
201 201
202 202
203static int matchbracketclass (l_char c, const l_char *p, const l_char *ec) { 203static int matchbracketclass (l_charint c, const l_char *p, const l_char *ec) {
204 int sig = 1; 204 int sig = 1;
205 if (*(p+1) == l_c('^')) { 205 if (*(p+1) == l_c('^')) {
206 sig = 0; 206 sig = 0;
@@ -214,16 +214,16 @@ static int matchbracketclass (l_char c, const l_char *p, const l_char *ec) {
214 } 214 }
215 else if ((*(p+1) == l_c('-')) && (p+2 < ec)) { 215 else if ((*(p+1) == l_c('-')) && (p+2 < ec)) {
216 p+=2; 216 p+=2;
217 if (uchar(*(p-2)) <= uchar(c) && uchar(c) <= uchar(*p)) 217 if (uchar(*(p-2)) <= c && c <= uchar(*p))
218 return sig; 218 return sig;
219 } 219 }
220 else if (*p == c) return sig; 220 else if (uchar(*p) == c) return sig;
221 } 221 }
222 return !sig; 222 return !sig;
223} 223}
224 224
225 225
226static int luaI_singlematch (l_char c, const l_char *p, const l_char *ep) { 226static int luaI_singlematch (l_charint c, const l_char *p, const l_char *ep) {
227 switch (*p) { 227 switch (*p) {
228 case l_c('.'): /* matches any char */ 228 case l_c('.'): /* matches any char */
229 return 1; 229 return 1;
@@ -232,7 +232,7 @@ static int luaI_singlematch (l_char c, const l_char *p, const l_char *ep) {
232 case l_c('['): 232 case l_c('['):
233 return matchbracketclass(c, p, ep-1); 233 return matchbracketclass(c, p, ep-1);
234 default: 234 default:
235 return (*p == c); 235 return (uchar(*p) == c);
236 } 236 }
237} 237}
238 238
@@ -263,7 +263,7 @@ static const l_char *matchbalance (MatchState *ms, const l_char *s,
263static const l_char *max_expand (MatchState *ms, const l_char *s, 263static const l_char *max_expand (MatchState *ms, const l_char *s,
264 const l_char *p, const l_char *ep) { 264 const l_char *p, const l_char *ep) {
265 sint32 i = 0; /* counts maximum expand for item */ 265 sint32 i = 0; /* counts maximum expand for item */
266 while ((s+i)<ms->src_end && luaI_singlematch(*(s+i), p, ep)) 266 while ((s+i)<ms->src_end && luaI_singlematch(uchar(*(s+i)), p, ep))
267 i++; 267 i++;
268 /* keeps trying to match with the maximum repetitions */ 268 /* keeps trying to match with the maximum repetitions */
269 while (i>=0) { 269 while (i>=0) {
@@ -281,7 +281,7 @@ static const l_char *min_expand (MatchState *ms, const l_char *s,
281 const l_char *res = match(ms, s, ep+1); 281 const l_char *res = match(ms, s, ep+1);
282 if (res != NULL) 282 if (res != NULL)
283 return res; 283 return res;
284 else if (s<ms->src_end && luaI_singlematch(*s, p, ep)) 284 else if (s<ms->src_end && luaI_singlematch(uchar(*s), p, ep))
285 s++; /* try with one more repetition */ 285 s++; /* try with one more repetition */
286 else return NULL; 286 else return NULL;
287 } 287 }
@@ -354,7 +354,7 @@ static const l_char *match (MatchState *ms, const l_char *s, const l_char *p) {
354 else goto dflt; 354 else goto dflt;
355 default: dflt: { /* it is a pattern item */ 355 default: dflt: { /* it is a pattern item */
356 const l_char *ep = luaI_classend(ms, p); /* points to what is next */ 356 const l_char *ep = luaI_classend(ms, p); /* points to what is next */
357 int m = s<ms->src_end && luaI_singlematch(*s, p, ep); 357 int m = s<ms->src_end && luaI_singlematch(uchar(*s), p, ep);
358 switch (*ep) { 358 switch (*ep) {
359 case l_c('?'): { /* optional */ 359 case l_c('?'): { /* optional */
360 const l_char *res; 360 const l_char *res;