| 338 | |
| 339 | |
| 340 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 341 | const char *r) { |
| 342 | const char *wild; |
| 343 | size_t l = strlen(p); |
| 344 | luaL_Buffer b; |
| 345 | luaL_buffinit(L, &b); |
| 346 | while ((wild = strstr(s, p)) != NULL) { |
| 347 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 348 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 349 | s = wild + l; /* continue after `p' */ |
| 350 | } |
| 351 | luaL_addstring(&b, s); /* push last suffix */ |
| 352 | luaL_pushresult(&b); |
| 353 | return lua_tostring(L, -1); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
no test coverage detected