diff options
Diffstat (limited to 'src/lj_str.c')
-rw-r--r-- | src/lj_str.c | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index f5bbae26..d21cecd0 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
@@ -13,7 +13,6 @@ | |||
13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
14 | #include "lj_buf.h" | 14 | #include "lj_buf.h" |
15 | #include "lj_str.h" | 15 | #include "lj_str.h" |
16 | #include "lj_state.h" | ||
17 | #include "lj_char.h" | 16 | #include "lj_char.h" |
18 | 17 | ||
19 | /* -- String helpers ------------------------------------------------------ */ | 18 | /* -- String helpers ------------------------------------------------------ */ |
@@ -316,68 +315,3 @@ GCstr * LJ_FASTCALL lj_str_fromchar(lua_State *L, int c) | |||
316 | return lj_str_new(L, buf, 1); | 315 | return lj_str_new(L, buf, 1); |
317 | } | 316 | } |
318 | 317 | ||
319 | /* -- String formatting --------------------------------------------------- */ | ||
320 | |||
321 | /* Push formatted message as a string object to Lua stack. va_list variant. */ | ||
322 | const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp) | ||
323 | { | ||
324 | SBuf *sb = &G(L)->tmpbuf; | ||
325 | setsbufL(sb, L); | ||
326 | lj_buf_need(sb, (MSize)strlen(fmt)); | ||
327 | lj_buf_reset(sb); | ||
328 | for (;;) { | ||
329 | const char *e = strchr(fmt, '%'); | ||
330 | if (e == NULL) break; | ||
331 | lj_buf_putmem(sb, fmt, (MSize)(e-fmt)); | ||
332 | /* This function only handles %s, %c, %d, %f and %p formats. */ | ||
333 | switch (e[1]) { | ||
334 | case 's': { | ||
335 | const char *s = va_arg(argp, char *); | ||
336 | if (s == NULL) s = "(null)"; | ||
337 | lj_buf_putmem(sb, s, (MSize)strlen(s)); | ||
338 | break; | ||
339 | } | ||
340 | case 'c': | ||
341 | lj_buf_putb(sb, va_arg(argp, int)); | ||
342 | break; | ||
343 | case 'd': | ||
344 | setsbufP(sb, lj_str_bufint(lj_buf_more(sb, LJ_STR_INTBUF), | ||
345 | va_arg(argp, int32_t))); | ||
346 | break; | ||
347 | case 'f': { | ||
348 | TValue tv; | ||
349 | tv.n = va_arg(argp, lua_Number); | ||
350 | setsbufP(sb, lj_str_bufnum(lj_buf_more(sb, LJ_STR_NUMBUF), &tv)); | ||
351 | break; | ||
352 | } | ||
353 | case 'p': | ||
354 | setsbufP(sb, lj_str_bufptr(lj_buf_more(sb, LJ_STR_PTRBUF), | ||
355 | va_arg(argp, void *))); | ||
356 | break; | ||
357 | case '%': | ||
358 | lj_buf_putb(sb, '%'); | ||
359 | break; | ||
360 | default: | ||
361 | lj_buf_putb(sb, '%'); | ||
362 | lj_buf_putb(sb, e[1]); | ||
363 | break; | ||
364 | } | ||
365 | fmt = e+2; | ||
366 | } | ||
367 | lj_buf_putmem(sb, fmt, (MSize)strlen(fmt)); | ||
368 | setstrV(L, L->top, lj_buf_str(L, sb)); | ||
369 | incr_top(L); | ||
370 | return strVdata(L->top - 1); | ||
371 | } | ||
372 | |||
373 | /* Push formatted message as a string object to Lua stack. Vararg variant. */ | ||
374 | const char *lj_str_pushf(lua_State *L, const char *fmt, ...) | ||
375 | { | ||
376 | const char *msg; | ||
377 | va_list argp; | ||
378 | va_start(argp, fmt); | ||
379 | msg = lj_str_pushvf(L, fmt, argp); | ||
380 | va_end(argp); | ||
381 | return msg; | ||
382 | } | ||
383 | |||