| 918 | |
| 919 | |
| 920 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 921 | const char *r) { |
| 922 | const char *wild; |
| 923 | size_t l = strlen(p); |
| 924 | luaL_Buffer b; |
| 925 | luaL_buffinit(L, &b); |
| 926 | while ((wild = strstr(s, p)) != NULL) { |
| 927 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 928 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 929 | s = wild + l; /* continue after 'p' */ |
| 930 | } |
| 931 | luaL_addstring(&b, s); /* push last suffix */ |
| 932 | luaL_pushresult(&b); |
| 933 | return lua_tostring(L, -1); |
| 934 | } |
| 935 | |
| 936 | |
| 937 | static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
no test coverage detected