diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-10 09:55:56 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-08-10 09:55:56 -0300 |
commit | 900257e8143b29a1d623eda3ec6d9f1b2a7267ab (patch) | |
tree | 72099c0b2ed24b47ac42f30611448098cea6eeea /lstrlib.c | |
parent | a82c8185bc351666c801ba437064becc41cd57a5 (diff) | |
download | lua-900257e8143b29a1d623eda3ec6d9f1b2a7267ab.tar.gz lua-900257e8143b29a1d623eda3ec6d9f1b2a7267ab.tar.bz2 lua-900257e8143b29a1d623eda3ec6d9f1b2a7267ab.zip |
char-set may contain '%]'
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 22 |
1 files changed, 11 insertions, 11 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.31 1999/05/14 12:24:04 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.32 1999/06/17 17:04:03 roberto Exp roberto $ |
3 | ** Standard library for strings and pattern-matching | 3 | ** Standard library for strings and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -102,7 +102,7 @@ static void str_char (void) { | |||
102 | int i = 0; | 102 | int i = 0; |
103 | luaL_resetbuffer(); | 103 | luaL_resetbuffer(); |
104 | while (lua_getparam(++i) != LUA_NOOBJECT) { | 104 | while (lua_getparam(++i) != LUA_NOOBJECT) { |
105 | double c = luaL_check_number(i); | 105 | int c = luaL_check_int(i); |
106 | luaL_arg_check((unsigned char)c == c, i, "invalid value"); | 106 | luaL_arg_check((unsigned char)c == c, i, "invalid value"); |
107 | luaL_addchar((unsigned char)c); | 107 | luaL_addchar((unsigned char)c); |
108 | } | 108 | } |
@@ -166,14 +166,14 @@ static int capture_to_close (struct Capture *cap) { | |||
166 | char *luaI_classend (char *p) { | 166 | char *luaI_classend (char *p) { |
167 | switch (*p++) { | 167 | switch (*p++) { |
168 | case ESC: | 168 | case ESC: |
169 | if (*p == '\0') | 169 | if (*p == '\0') lua_error("incorrect pattern (ends with `%')"); |
170 | luaL_verror("incorrect pattern (ends with `%c')", ESC); | ||
171 | return p+1; | 170 | return p+1; |
172 | case '[': | 171 | case '[': |
173 | if (*p == '^') p++; | 172 | if (*p == '^') p++; |
174 | if (*p == ']') p++; | 173 | do { /* look for a ']' */ |
175 | p = strchr(p, ']'); | 174 | if (*p == '\0') lua_error("incorrect pattern (missing `]')"); |
176 | if (!p) lua_error("incorrect pattern (missing `]')"); | 175 | if (*(p++) == ESC && *p != '\0') p++; /* skip escapes (e.g. '%]') */ |
176 | } while (*p != ']'); | ||
177 | return p+1; | 177 | return p+1; |
178 | default: | 178 | default: |
179 | return p; | 179 | return p; |
@@ -201,19 +201,19 @@ static int matchclass (int c, int cl) { | |||
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | static int matchbracketclass (int c, char *p, char *end) { | 204 | static int matchbracketclass (int c, char *p, char *endclass) { |
205 | int sig = 1; | 205 | int sig = 1; |
206 | if (*(p+1) == '^') { | 206 | if (*(p+1) == '^') { |
207 | sig = 0; | 207 | sig = 0; |
208 | p++; /* skip the '^' */ | 208 | p++; /* skip the '^' */ |
209 | } | 209 | } |
210 | while (++p < end) { | 210 | while (++p < endclass) { |
211 | if (*p == ESC) { | 211 | if (*p == ESC) { |
212 | p++; | 212 | p++; |
213 | if ((p < end) && matchclass(c, (unsigned char)*p)) | 213 | if (matchclass(c, (unsigned char)*p)) |
214 | return sig; | 214 | return sig; |
215 | } | 215 | } |
216 | else if ((*(p+1) == '-') && (p+2 < end)) { | 216 | else if ((*(p+1) == '-') && (p+2 < endclass)) { |
217 | p+=2; | 217 | p+=2; |
218 | if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p) | 218 | if ((int)(unsigned char)*(p-2) <= c && c <= (int)(unsigned char)*p) |
219 | return sig; | 219 | return sig; |