aboutsummaryrefslogtreecommitdiff
path: root/lstrlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstrlib.c')
-rw-r--r--lstrlib.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/lstrlib.c b/lstrlib.c
index e1aee1fd..e4be9f58 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.96 2003/03/14 18:59:53 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.97 2003/03/19 21:16:12 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*/
@@ -31,7 +31,7 @@ typedef long sint32; /* a signed version for size_t */
31static int str_len (lua_State *L) { 31static int str_len (lua_State *L) {
32 size_t l; 32 size_t l;
33 luaL_checklstring(L, 1, &l); 33 luaL_checklstring(L, 1, &l);
34 lua_pushnumber(L, l); 34 lua_pushnumber(L, (lua_Number)l);
35 return 1; 35 return 1;
36} 36}
37 37
@@ -48,7 +48,7 @@ static int str_sub (lua_State *L) {
48 sint32 start = posrelat(luaL_checklong(L, 2), l); 48 sint32 start = posrelat(luaL_checklong(L, 2), l);
49 sint32 end = posrelat(luaL_optlong(L, 3, -1), l); 49 sint32 end = posrelat(luaL_optlong(L, 3, -1), l);
50 if (start < 1) start = 1; 50 if (start < 1) start = 1;
51 if (end > (sint32)l) end = l; 51 if (end > (sint32)l) end = (sint32)l;
52 if (start <= end) 52 if (start <= end)
53 lua_pushlstring(L, s+start-1, end-start+1); 53 lua_pushlstring(L, s+start-1, end-start+1);
54 else lua_pushliteral(L, ""); 54 else lua_pushliteral(L, "");
@@ -452,7 +452,7 @@ static void push_onecapture (MatchState *ms, int i) {
452 int l = ms->capture[i].len; 452 int l = ms->capture[i].len;
453 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); 453 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
454 if (l == CAP_POSITION) 454 if (l == CAP_POSITION)
455 lua_pushnumber(ms->L, ms->capture[i].init - ms->src_init + 1); 455 lua_pushnumber(ms->L, (lua_Number)(ms->capture[i].init - ms->src_init + 1));
456 else 456 else
457 lua_pushlstring(ms->L, ms->capture[i].init, l); 457 lua_pushlstring(ms->L, ms->capture[i].init, l);
458} 458}
@@ -479,14 +479,14 @@ static int str_find (lua_State *L) {
479 const char *p = luaL_checklstring(L, 2, &l2); 479 const char *p = luaL_checklstring(L, 2, &l2);
480 sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1; 480 sint32 init = posrelat(luaL_optlong(L, 3, 1), l1) - 1;
481 if (init < 0) init = 0; 481 if (init < 0) init = 0;
482 else if ((size_t)(init) > l1) init = l1; 482 else if ((size_t)(init) > l1) init = (sint32)l1;
483 if (lua_toboolean(L, 4) || /* explicit request? */ 483 if (lua_toboolean(L, 4) || /* explicit request? */
484 strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */ 484 strpbrk(p, SPECIALS) == NULL) { /* or no special characters? */
485 /* do a plain search */ 485 /* do a plain search */
486 const char *s2 = lmemfind(s+init, l1-init, p, l2); 486 const char *s2 = lmemfind(s+init, l1-init, p, l2);
487 if (s2) { 487 if (s2) {
488 lua_pushnumber(L, s2-s+1); 488 lua_pushnumber(L, (lua_Number)(s2-s+1));
489 lua_pushnumber(L, s2-s+l2); 489 lua_pushnumber(L, (lua_Number)(s2-s+l2));
490 return 2; 490 return 2;
491 } 491 }
492 } 492 }
@@ -501,8 +501,8 @@ static int str_find (lua_State *L) {
501 const char *res; 501 const char *res;
502 ms.level = 0; 502 ms.level = 0;
503 if ((res=match(&ms, s1, p)) != NULL) { 503 if ((res=match(&ms, s1, p)) != NULL) {
504 lua_pushnumber(L, s1-s+1); /* start */ 504 lua_pushnumber(L, (lua_Number)(s1-s+1)); /* start */
505 lua_pushnumber(L, res-s); /* end */ 505 lua_pushnumber(L, (lua_Number)(res-s)); /* end */
506 return push_captures(&ms, NULL, 0) + 2; 506 return push_captures(&ms, NULL, 0) + 2;
507 } 507 }
508 } while (s1++<ms.src_end && !anchor); 508 } while (s1++<ms.src_end && !anchor);
@@ -529,7 +529,7 @@ static int gfind_aux (lua_State *L) {
529 if ((e = match(&ms, src, p)) != NULL) { 529 if ((e = match(&ms, src, p)) != NULL) {
530 int newstart = e-s; 530 int newstart = e-s;
531 if (e == src) newstart++; /* empty match? go at least one position */ 531 if (e == src) newstart++; /* empty match? go at least one position */
532 lua_pushnumber(L, newstart); 532 lua_pushnumber(L, (lua_Number)newstart);
533 lua_replace(L, lua_upvalueindex(3)); 533 lua_replace(L, lua_upvalueindex(3));
534 return push_captures(&ms, src, e); 534 return push_captures(&ms, src, e);
535 } 535 }
@@ -616,7 +616,7 @@ static int str_gsub (lua_State *L) {
616 } 616 }
617 luaL_addlstring(&b, src, ms.src_end-src); 617 luaL_addlstring(&b, src, ms.src_end-src);
618 luaL_pushresult(&b); 618 luaL_pushresult(&b);
619 lua_pushnumber(L, n); /* number of substitutions */ 619 lua_pushnumber(L, (lua_Number)n); /* number of substitutions */
620 return 2; 620 return 2;
621} 621}
622 622