aboutsummaryrefslogtreecommitdiff
path: root/src/lj_strfmt.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_strfmt.h')
-rw-r--r--src/lj_strfmt.h51
1 files changed, 40 insertions, 11 deletions
diff --git a/src/lj_strfmt.h b/src/lj_strfmt.h
index 6f3dc0be..5454336f 100644
--- a/src/lj_strfmt.h
+++ b/src/lj_strfmt.h
@@ -65,6 +65,15 @@ typedef enum FormatType {
65#define STRFMT_U (STRFMT_UINT) 65#define STRFMT_U (STRFMT_UINT)
66#define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX) 66#define STRFMT_X (STRFMT_UINT|STRFMT_T_HEX)
67 67
68/* Maximum buffer sizes for conversions. */
69#define STRFMT_MAXBUF_XINT (1+22) /* '0' prefix + uint64_t in octal. */
70#define STRFMT_MAXBUF_INT (1+10) /* Sign + int32_t in decimal. */
71#define STRFMT_MAXBUF_NUM LUAI_MAXNUMBER2STR
72#define STRFMT_MAXBUF_PTR (2+2*sizeof(ptrdiff_t)) /* "0x" + hex ptr. */
73
74/* Format parser. */
75LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs);
76
68static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) 77static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len)
69{ 78{
70 fs->p = (const uint8_t *)p; 79 fs->p = (const uint8_t *)p;
@@ -72,18 +81,38 @@ static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len)
72 lua_assert(*fs->e == 0); /* Must be NUL-terminated (may have NULs inside). */ 81 lua_assert(*fs->e == 0); /* Must be NUL-terminated (may have NULs inside). */
73} 82}
74 83
75LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); 84/* Raw conversions. */
76 85LJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k);
77LJ_FUNC SBuf *lj_strfmt_putchar(SBuf *sb, SFormat, int32_t c); 86LJ_FUNC char * LJ_FASTCALL lj_strfmt_wnum(char *p, cTValue *o);
78LJ_FUNC SBuf *lj_strfmt_putstr(SBuf *sb, SFormat, GCstr *str); 87LJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v);
79LJ_FUNC SBuf *lj_strfmt_putquoted(SBuf *sb, GCstr *str); 88LJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v);
80LJ_FUNC SBuf *lj_strfmt_putxint(SBuf *sb, SFormat sf, uint64_t k); 89LJ_FUNC const char *lj_strfmt_wstrnum(char *buf, cTValue *o, MSize *lenp);
81LJ_FUNC SBuf *lj_strfmt_putnum_int(SBuf *sb, SFormat sf, lua_Number n); 90
82LJ_FUNC SBuf *lj_strfmt_putnum_uint(SBuf *sb, SFormat sf, lua_Number n); 91/* Unformatted conversions to buffer. */
83LJ_FUNC SBuf *lj_strfmt_putnum(SBuf *sb, SFormat, lua_Number n); 92LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k);
84 93#if LJ_HASJIT
85LJ_FUNC GCstr *lj_strfmt_obj(lua_State *L, cTValue *o); 94LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o);
95#endif
96LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str);
97
98/* Formatted conversions to buffer. */
99LJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k);
100LJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n);
101LJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n);
102LJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n);
103LJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c);
104LJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str);
105
106/* Conversions to strings. */
107LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k);
108LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o);
109LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o);
110#if LJ_HASJIT
111LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c);
112#endif
113LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o);
86 114
115/* Internal string formatting. */
87LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, 116LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt,
88 va_list argp); 117 va_list argp);
89LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) 118LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)