| 363 | |
| 364 | |
| 365 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 366 | const char *r) { |
| 367 | const char *wild; |
| 368 | size_t l = strlen(p); |
| 369 | luaL_Buffer b; |
| 370 | luaL_buffinit(L, &b); |
| 371 | while ((wild = strstr(s, p)) != NULL) { |
| 372 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 373 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 374 | s = wild + l; /* continue after `p' */ |
| 375 | } |
| 376 | luaL_addstring(&b, s); /* push last suffix */ |
| 377 | luaL_pushresult(&b); |
| 378 | return lua_tostring(L, -1); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
no test coverage detected