diff options
Diffstat (limited to 'src/lj_strfmt.h')
-rw-r--r-- | src/lj_strfmt.h | 51 |
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. */ | ||
75 | LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); | ||
76 | |||
68 | static LJ_AINLINE void lj_strfmt_init(FormatState *fs, const char *p, MSize len) | 77 | static 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 | ||
75 | LJ_FUNC SFormat LJ_FASTCALL lj_strfmt_parse(FormatState *fs); | 84 | /* Raw conversions. */ |
76 | 85 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wint(char *p, int32_t k); | |
77 | LJ_FUNC SBuf *lj_strfmt_putchar(SBuf *sb, SFormat, int32_t c); | 86 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wnum(char *p, cTValue *o); |
78 | LJ_FUNC SBuf *lj_strfmt_putstr(SBuf *sb, SFormat, GCstr *str); | 87 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wptr(char *p, const void *v); |
79 | LJ_FUNC SBuf *lj_strfmt_putquoted(SBuf *sb, GCstr *str); | 88 | LJ_FUNC char * LJ_FASTCALL lj_strfmt_wuleb128(char *p, uint32_t v); |
80 | LJ_FUNC SBuf *lj_strfmt_putxint(SBuf *sb, SFormat sf, uint64_t k); | 89 | LJ_FUNC const char *lj_strfmt_wstrnum(char *buf, cTValue *o, MSize *lenp); |
81 | LJ_FUNC SBuf *lj_strfmt_putnum_int(SBuf *sb, SFormat sf, lua_Number n); | 90 | |
82 | LJ_FUNC SBuf *lj_strfmt_putnum_uint(SBuf *sb, SFormat sf, lua_Number n); | 91 | /* Unformatted conversions to buffer. */ |
83 | LJ_FUNC SBuf *lj_strfmt_putnum(SBuf *sb, SFormat, lua_Number n); | 92 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putint(SBuf *sb, int32_t k); |
84 | 93 | #if LJ_HASJIT | |
85 | LJ_FUNC GCstr *lj_strfmt_obj(lua_State *L, cTValue *o); | 94 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putnum(SBuf *sb, cTValue *o); |
95 | #endif | ||
96 | LJ_FUNC SBuf * LJ_FASTCALL lj_strfmt_putquoted(SBuf *sb, GCstr *str); | ||
97 | |||
98 | /* Formatted conversions to buffer. */ | ||
99 | LJ_FUNC SBuf *lj_strfmt_putfxint(SBuf *sb, SFormat sf, uint64_t k); | ||
100 | LJ_FUNC SBuf *lj_strfmt_putfnum_int(SBuf *sb, SFormat sf, lua_Number n); | ||
101 | LJ_FUNC SBuf *lj_strfmt_putfnum_uint(SBuf *sb, SFormat sf, lua_Number n); | ||
102 | LJ_FUNC SBuf *lj_strfmt_putfnum(SBuf *sb, SFormat, lua_Number n); | ||
103 | LJ_FUNC SBuf *lj_strfmt_putfchar(SBuf *sb, SFormat, int32_t c); | ||
104 | LJ_FUNC SBuf *lj_strfmt_putfstr(SBuf *sb, SFormat, GCstr *str); | ||
105 | |||
106 | /* Conversions to strings. */ | ||
107 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_int(lua_State *L, int32_t k); | ||
108 | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_num(lua_State *L, cTValue *o); | ||
109 | LJ_FUNCA GCstr * LJ_FASTCALL lj_strfmt_number(lua_State *L, cTValue *o); | ||
110 | #if LJ_HASJIT | ||
111 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_char(lua_State *L, int c); | ||
112 | #endif | ||
113 | LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o); | ||
86 | 114 | ||
115 | /* Internal string formatting. */ | ||
87 | LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, | 116 | LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt, |
88 | va_list argp); | 117 | va_list argp); |
89 | LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) | 118 | LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...) |