| 900 | |
| 901 | |
| 902 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 903 | const char *r) { |
| 904 | const char *wild; |
| 905 | size_t l = strlen(p); |
| 906 | luaL_Buffer b; |
| 907 | luaL_buffinit(L, &b); |
| 908 | while ((wild = strstr(s, p)) != NULL) { |
| 909 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 910 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 911 | s = wild + l; /* continue after `p' */ |
| 912 | } |
| 913 | luaL_addstring(&b, s); /* push last suffix */ |
| 914 | luaL_pushresult(&b); |
| 915 | return lua_tostring(L, -1); |
| 916 | } |
| 917 | |
| 918 | |
| 919 | static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
no test coverage detected