| 989 | |
| 990 | |
| 991 | LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, |
| 992 | const char *r) { |
| 993 | const char *wild; |
| 994 | size_t l = strlen(p); |
| 995 | luaL_Buffer b; |
| 996 | luaL_buffinit(L, &b); |
| 997 | while ((wild = strstr(s, p)) != NULL) { |
| 998 | luaL_addlstring(&b, s, wild - s); /* push prefix */ |
| 999 | luaL_addstring(&b, r); /* push replacement in place of pattern */ |
| 1000 | s = wild + l; /* continue after 'p' */ |
| 1001 | } |
| 1002 | luaL_addstring(&b, s); /* push last suffix */ |
| 1003 | luaL_pushresult(&b); |
| 1004 | return lua_tostring(L, -1); |
| 1005 | } |
| 1006 | |
| 1007 | |
| 1008 | static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) { |
no test coverage detected