diff options
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -951,18 +951,24 @@ LUALIB_API void luaL_requiref (lua_State *L, const char *modname, | |||
951 | } | 951 | } |
952 | 952 | ||
953 | 953 | ||
954 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | 954 | LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s, |
955 | const char *r) { | 955 | const char *p, const char *r) { |
956 | const char *wild; | 956 | const char *wild; |
957 | size_t l = strlen(p); | 957 | size_t l = strlen(p); |
958 | luaL_Buffer b; | ||
959 | luaL_buffinit(L, &b); | ||
960 | while ((wild = strstr(s, p)) != NULL) { | 958 | while ((wild = strstr(s, p)) != NULL) { |
961 | luaL_addlstring(&b, s, wild - s); /* push prefix */ | 959 | luaL_addlstring(b, s, wild - s); /* push prefix */ |
962 | luaL_addstring(&b, r); /* push replacement in place of pattern */ | 960 | luaL_addstring(b, r); /* push replacement in place of pattern */ |
963 | s = wild + l; /* continue after 'p' */ | 961 | s = wild + l; /* continue after 'p' */ |
964 | } | 962 | } |
965 | luaL_addstring(&b, s); /* push last suffix */ | 963 | luaL_addstring(b, s); /* push last suffix */ |
964 | } | ||
965 | |||
966 | |||
967 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, | ||
968 | const char *p, const char *r) { | ||
969 | luaL_Buffer b; | ||
970 | luaL_buffinit(L, &b); | ||
971 | luaL_addgsub(&b, s, p, r); | ||
966 | luaL_pushresult(&b); | 972 | luaL_pushresult(&b); |
967 | return lua_tostring(L, -1); | 973 | return lua_tostring(L, -1); |
968 | } | 974 | } |