aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-02 14:12:27 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2002-05-02 14:12:27 -0300
commit85dcb411a8454de0bc1c2c60a24af1588e436c23 (patch)
tree169fc4cefe7ba02a46944a172660aff208b3e42e /lstrlib.c
parent3c6a383d6239629fd8858e0d59bcdab25138bcc1 (diff)
downloadlua-85dcb411a8454de0bc1c2c60a24af1588e436c23.tar.gz
lua-85dcb411a8454de0bc1c2c60a24af1588e436c23.tar.bz2
lua-85dcb411a8454de0bc1c2c60a24af1588e436c23.zip
all textual errors go through `luaL_verror'
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 648a081b..b308b78e 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.79 2002/03/20 12:54:08 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.80 2002/04/02 20:41:59 roberto Exp roberto $
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*/
@@ -170,7 +170,7 @@ typedef struct MatchState {
170static int check_capture (MatchState *ms, int l) { 170static int check_capture (MatchState *ms, int l) {
171 l -= '1'; 171 l -= '1';
172 if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED) 172 if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
173 lua_error(ms->L, "invalid capture index"); 173 luaL_verror(ms->L, "invalid capture index");
174 return l; 174 return l;
175} 175}
176 176
@@ -179,7 +179,7 @@ static int capture_to_close (MatchState *ms) {
179 int level = ms->level; 179 int level = ms->level;
180 for (level--; level>=0; level--) 180 for (level--; level>=0; level--)
181 if (ms->capture[level].len == CAP_UNFINISHED) return level; 181 if (ms->capture[level].len == CAP_UNFINISHED) return level;
182 lua_error(ms->L, "invalid pattern capture"); 182 luaL_verror(ms->L, "invalid pattern capture");
183 return 0; /* to avoid warnings */ 183 return 0; /* to avoid warnings */
184} 184}
185 185
@@ -188,13 +188,13 @@ static const char *luaI_classend (MatchState *ms, const char *p) {
188 switch (*p++) { 188 switch (*p++) {
189 case ESC: 189 case ESC:
190 if (*p == '\0') 190 if (*p == '\0')
191 lua_error(ms->L, "malformed pattern (ends with `%')"); 191 luaL_verror(ms->L, "malformed pattern (ends with `%')");
192 return p+1; 192 return p+1;
193 case '[': 193 case '[':
194 if (*p == '^') p++; 194 if (*p == '^') p++;
195 do { /* look for a `]' */ 195 do { /* look for a `]' */
196 if (*p == '\0') 196 if (*p == '\0')
197 lua_error(ms->L, "malformed pattern (missing `]')"); 197 luaL_verror(ms->L, "malformed pattern (missing `]')");
198 if (*(p++) == ESC && *p != '\0') 198 if (*(p++) == ESC && *p != '\0')
199 p++; /* skip escapes (e.g. `%]') */ 199 p++; /* skip escapes (e.g. `%]') */
200 } while (*p != ']'); 200 } while (*p != ']');
@@ -267,7 +267,7 @@ static const char *match (MatchState *ms, const char *s, const char *p);
267static const char *matchbalance (MatchState *ms, const char *s, 267static const char *matchbalance (MatchState *ms, const char *s,
268 const char *p) { 268 const char *p) {
269 if (*p == 0 || *(p+1) == 0) 269 if (*p == 0 || *(p+1) == 0)
270 lua_error(ms->L, "unbalanced pattern"); 270 luaL_verror(ms->L, "unbalanced pattern");
271 if (*s != *p) return NULL; 271 if (*s != *p) return NULL;
272 else { 272 else {
273 int b = *p; 273 int b = *p;
@@ -316,7 +316,7 @@ static const char *start_capture (MatchState *ms, const char *s,
316 const char *p, int what) { 316 const char *p, int what) {
317 const char *res; 317 const char *res;
318 int level = ms->level; 318 int level = ms->level;
319 if (level >= MAX_CAPTURES) lua_error(ms->L, "too many captures"); 319 if (level >= MAX_CAPTURES) luaL_verror(ms->L, "too many captures");
320 ms->capture[level].init = s; 320 ms->capture[level].init = s;
321 ms->capture[level].len = what; 321 ms->capture[level].len = what;
322 ms->level = level+1; 322 ms->level = level+1;
@@ -426,7 +426,7 @@ static const char *lmemfind (const char *s1, size_t l1,
426 426
427static void push_onecapture (MatchState *ms, int i) { 427static void push_onecapture (MatchState *ms, int i) {
428 int l = ms->capture[i].len; 428 int l = ms->capture[i].len;
429 if (l == CAP_UNFINISHED) lua_error(ms->L, "unfinished capture"); 429 if (l == CAP_UNFINISHED) luaL_verror(ms->L, "unfinished capture");
430 if (l == CAP_POSITION) 430 if (l == CAP_POSITION)
431 lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); 431 lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1);
432 else 432 else
@@ -636,9 +636,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt,
636 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */ 636 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
637 } 637 }
638 if (isdigit(uchar(*p))) 638 if (isdigit(uchar(*p)))
639 lua_error(L, "invalid format (width or precision too long)"); 639 luaL_verror(L, "invalid format (width or precision too long)");
640 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */ 640 if (p-strfrmt+2 > MAX_FORMAT) /* +2 to include `%' and the specifier */
641 lua_error(L, "invalid format (too long)"); 641 luaL_verror(L, "invalid format (too long)");
642 form[0] = '%'; 642 form[0] = '%';
643 strncpy(form+1, strfrmt, p-strfrmt+1); 643 strncpy(form+1, strfrmt, p-strfrmt+1);
644 form[p-strfrmt+2] = 0; 644 form[p-strfrmt+2] = 0;
@@ -663,7 +663,7 @@ static int str_format (lua_State *L) {
663 char buff[MAX_ITEM]; /* to store the formatted item */ 663 char buff[MAX_ITEM]; /* to store the formatted item */
664 int hasprecision = 0; 664 int hasprecision = 0;
665 if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$') 665 if (isdigit(uchar(*strfrmt)) && *(strfrmt+1) == '$')
666 lua_error(L, "obsolete `format' option (d$)"); 666 luaL_verror(L, "obsolete `format' option (d$)");
667 arg++; 667 arg++;
668 strfrmt = scanformat(L, strfrmt, form, &hasprecision); 668 strfrmt = scanformat(L, strfrmt, form, &hasprecision);
669 switch (*strfrmt++) { 669 switch (*strfrmt++) {
@@ -696,7 +696,7 @@ static int str_format (lua_State *L) {
696 } 696 }
697 } 697 }
698 default: /* also treat cases `pnLlh' */ 698 default: /* also treat cases `pnLlh' */
699 lua_error(L, "invalid option in `format'"); 699 luaL_verror(L, "invalid option in `format'");
700 } 700 }
701 luaL_addlstring(&b, buff, strlen(buff)); 701 luaL_addlstring(&b, buff, strlen(buff));
702 } 702 }