| 386 | |
| 387 | |
| 388 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 389 | const char *r) { |
| 390 | const char *wild; |
| 391 | size_t l = strlen(p); |
| 392 | luaL_Buffer b; |
| 393 | luaL_buffinit(L, &b); |
| 394 | while ((wild = strstr(s, p)) != NULL) { |
| 395 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 396 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 397 | s = wild + l; /* continue after `p' */ |
| 398 | } |
| 399 | luaL_addstring(&b, s); /* push last suffix */ |
| 400 | luaL_pushresult(&b); |
| 401 | return lua_tostring(L, -1); |
| 402 | } |
| 403 | |
| 404 | |
| 405 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
no test coverage detected