diff options
Diffstat (limited to 'lstrlib.c')
-rw-r--r-- | lstrlib.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.120 2005/07/31 16:47:34 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.121 2005/08/09 17:42:02 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 | */ |
@@ -58,7 +58,7 @@ static int str_reverse (lua_State *L) { | |||
58 | luaL_Buffer b; | 58 | luaL_Buffer b; |
59 | const char *s = luaL_checklstring(L, 1, &l); | 59 | const char *s = luaL_checklstring(L, 1, &l); |
60 | luaL_buffinit(L, &b); | 60 | luaL_buffinit(L, &b); |
61 | while (l--) luaL_putchar(&b, s[l]); | 61 | while (l--) luaL_addchar(&b, s[l]); |
62 | luaL_pushresult(&b); | 62 | luaL_pushresult(&b); |
63 | return 1; | 63 | return 1; |
64 | } | 64 | } |
@@ -71,7 +71,7 @@ static int str_lower (lua_State *L) { | |||
71 | const char *s = luaL_checklstring(L, 1, &l); | 71 | const char *s = luaL_checklstring(L, 1, &l); |
72 | luaL_buffinit(L, &b); | 72 | luaL_buffinit(L, &b); |
73 | for (i=0; i<l; i++) | 73 | for (i=0; i<l; i++) |
74 | luaL_putchar(&b, tolower(uchar(s[i]))); | 74 | luaL_addchar(&b, tolower(uchar(s[i]))); |
75 | luaL_pushresult(&b); | 75 | luaL_pushresult(&b); |
76 | return 1; | 76 | return 1; |
77 | } | 77 | } |
@@ -84,7 +84,7 @@ static int str_upper (lua_State *L) { | |||
84 | const char *s = luaL_checklstring(L, 1, &l); | 84 | const char *s = luaL_checklstring(L, 1, &l); |
85 | luaL_buffinit(L, &b); | 85 | luaL_buffinit(L, &b); |
86 | for (i=0; i<l; i++) | 86 | for (i=0; i<l; i++) |
87 | luaL_putchar(&b, toupper(uchar(s[i]))); | 87 | luaL_addchar(&b, toupper(uchar(s[i]))); |
88 | luaL_pushresult(&b); | 88 | luaL_pushresult(&b); |
89 | return 1; | 89 | return 1; |
90 | } | 90 | } |
@@ -127,7 +127,7 @@ static int str_char (lua_State *L) { | |||
127 | for (i=1; i<=n; i++) { | 127 | for (i=1; i<=n; i++) { |
128 | int c = luaL_checkint(L, i); | 128 | int c = luaL_checkint(L, i); |
129 | luaL_argcheck(L, uchar(c) == c, i, "invalid value"); | 129 | luaL_argcheck(L, uchar(c) == c, i, "invalid value"); |
130 | luaL_putchar(&b, uchar(c)); | 130 | luaL_addchar(&b, uchar(c)); |
131 | } | 131 | } |
132 | luaL_pushresult(&b); | 132 | luaL_pushresult(&b); |
133 | return 1; | 133 | return 1; |
@@ -594,11 +594,11 @@ static void add_s (MatchState *ms, luaL_Buffer *b, | |||
594 | size_t i; | 594 | size_t i; |
595 | for (i=0; i<l; i++) { | 595 | for (i=0; i<l; i++) { |
596 | if (news[i] != L_ESC) | 596 | if (news[i] != L_ESC) |
597 | luaL_putchar(b, news[i]); | 597 | luaL_addchar(b, news[i]); |
598 | else { | 598 | else { |
599 | i++; /* skip ESC */ | 599 | i++; /* skip ESC */ |
600 | if (!isdigit(uchar(news[i]))) | 600 | if (!isdigit(uchar(news[i]))) |
601 | luaL_putchar(b, news[i]); | 601 | luaL_addchar(b, news[i]); |
602 | else { | 602 | else { |
603 | if (news[i] == '0') | 603 | if (news[i] == '0') |
604 | lua_pushlstring(L, s, e - s); /* add whole match */ | 604 | lua_pushlstring(L, s, e - s); /* add whole match */ |
@@ -651,7 +651,7 @@ static int str_gsub (lua_State *L) { | |||
651 | if (e && e>src) /* non empty match? */ | 651 | if (e && e>src) /* non empty match? */ |
652 | src = e; /* skip it */ | 652 | src = e; /* skip it */ |
653 | else if (src < ms.src_end) | 653 | else if (src < ms.src_end) |
654 | luaL_putchar(&b, *src++); | 654 | luaL_addchar(&b, *src++); |
655 | else break; | 655 | else break; |
656 | if (anchor) break; | 656 | if (anchor) break; |
657 | } | 657 | } |
@@ -673,12 +673,12 @@ static int str_gsub (lua_State *L) { | |||
673 | static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { | 673 | static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { |
674 | size_t l; | 674 | size_t l; |
675 | const char *s = luaL_checklstring(L, arg, &l); | 675 | const char *s = luaL_checklstring(L, arg, &l); |
676 | luaL_putchar(b, '"'); | 676 | luaL_addchar(b, '"'); |
677 | while (l--) { | 677 | while (l--) { |
678 | switch (*s) { | 678 | switch (*s) { |
679 | case '"': case '\\': case '\n': { | 679 | case '"': case '\\': case '\n': { |
680 | luaL_putchar(b, '\\'); | 680 | luaL_addchar(b, '\\'); |
681 | luaL_putchar(b, *s); | 681 | luaL_addchar(b, *s); |
682 | break; | 682 | break; |
683 | } | 683 | } |
684 | case '\0': { | 684 | case '\0': { |
@@ -686,13 +686,13 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) { | |||
686 | break; | 686 | break; |
687 | } | 687 | } |
688 | default: { | 688 | default: { |
689 | luaL_putchar(b, *s); | 689 | luaL_addchar(b, *s); |
690 | break; | 690 | break; |
691 | } | 691 | } |
692 | } | 692 | } |
693 | s++; | 693 | s++; |
694 | } | 694 | } |
695 | luaL_putchar(b, '"'); | 695 | luaL_addchar(b, '"'); |
696 | } | 696 | } |
697 | 697 | ||
698 | 698 | ||
@@ -728,9 +728,9 @@ static int str_format (lua_State *L) { | |||
728 | luaL_buffinit(L, &b); | 728 | luaL_buffinit(L, &b); |
729 | while (strfrmt < strfrmt_end) { | 729 | while (strfrmt < strfrmt_end) { |
730 | if (*strfrmt != L_ESC) | 730 | if (*strfrmt != L_ESC) |
731 | luaL_putchar(&b, *strfrmt++); | 731 | luaL_addchar(&b, *strfrmt++); |
732 | else if (*++strfrmt == L_ESC) | 732 | else if (*++strfrmt == L_ESC) |
733 | luaL_putchar(&b, *strfrmt++); /* %% */ | 733 | luaL_addchar(&b, *strfrmt++); /* %% */ |
734 | else { /* format item */ | 734 | else { /* format item */ |
735 | char form[MAX_FORMAT]; /* to store the format (`%...') */ | 735 | char form[MAX_FORMAT]; /* to store the format (`%...') */ |
736 | char buff[MAX_ITEM]; /* to store the formatted item */ | 736 | char buff[MAX_ITEM]; /* to store the formatted item */ |
@@ -818,7 +818,7 @@ static void createmetatable (lua_State *L) { | |||
818 | ** Open string library | 818 | ** Open string library |
819 | */ | 819 | */ |
820 | LUALIB_API int luaopen_string (lua_State *L) { | 820 | LUALIB_API int luaopen_string (lua_State *L) { |
821 | luaL_openlib(L, LUA_STRLIBNAME, strlib, 0); | 821 | luaL_register(L, LUA_STRLIBNAME, strlib); |
822 | #if defined(LUA_COMPAT_GFIND) | 822 | #if defined(LUA_COMPAT_GFIND) |
823 | lua_getfield(L, -1, "gmatch"); | 823 | lua_getfield(L, -1, "gmatch"); |
824 | lua_setfield(L, -2, "gfind"); | 824 | lua_setfield(L, -2, "gfind"); |