diff options
Diffstat (limited to '')
-rw-r--r-- | src/lj_str.c | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index d21cecd0..24d96067 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
@@ -11,7 +11,6 @@ | |||
11 | #include "lj_obj.h" | 11 | #include "lj_obj.h" |
12 | #include "lj_gc.h" | 12 | #include "lj_gc.h" |
13 | #include "lj_err.h" | 13 | #include "lj_err.h" |
14 | #include "lj_buf.h" | ||
15 | #include "lj_str.h" | 14 | #include "lj_str.h" |
16 | #include "lj_char.h" | 15 | #include "lj_char.h" |
17 | 16 | ||
@@ -198,120 +197,3 @@ void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) | |||
198 | lj_mem_free(g, s, sizestring(s)); | 197 | lj_mem_free(g, s, sizestring(s)); |
199 | } | 198 | } |
200 | 199 | ||
201 | /* -- Type conversions ---------------------------------------------------- */ | ||
202 | |||
203 | /* Print number to buffer. Canonicalizes non-finite values. */ | ||
204 | char * LJ_FASTCALL lj_str_bufnum(char *p, cTValue *o) | ||
205 | { | ||
206 | if (LJ_LIKELY((o->u32.hi << 1) < 0xffe00000)) { /* Finite? */ | ||
207 | #if __BIONIC__ | ||
208 | if (tvismzero(o)) { *p++ = '-'; *p++ = '0'; return p; } | ||
209 | #endif | ||
210 | return p + lua_number2str(p, o->n); | ||
211 | } else if (((o->u32.hi & 0x000fffff) | o->u32.lo) != 0) { | ||
212 | *p++ = 'n'; *p++ = 'a'; *p++ = 'n'; | ||
213 | } else if ((o->u32.hi & 0x80000000) == 0) { | ||
214 | *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
215 | } else { | ||
216 | *p++ = '-'; *p++ = 'i'; *p++ = 'n'; *p++ = 'f'; | ||
217 | } | ||
218 | return p; | ||
219 | } | ||
220 | |||
221 | #define STR_BUFINT_R(x, sh, sc) \ | ||
222 | { uint32_t d = (x*(((1<<sh)+sc-1)/sc))>>sh; x -= d*sc; *p++ = (char)('0'+d); } | ||
223 | |||
224 | /* Print integer to buffer. */ | ||
225 | char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k) | ||
226 | { | ||
227 | uint32_t u = (uint32_t)k; | ||
228 | if (k < 0) { u = (uint32_t)-k; *p++ = '-'; } | ||
229 | if (u < 10000) { | ||
230 | if (u < 10) goto dig1; if (u < 100) goto dig2; if (u < 1000) goto dig3; | ||
231 | } else { | ||
232 | uint32_t v = u / 10000; u -= v * 10000; | ||
233 | if (v < 10000) { | ||
234 | if (v < 10) goto dig5; if (v < 100) goto dig6; if (v < 1000) goto dig7; | ||
235 | } else { | ||
236 | uint32_t w = v / 10000; v -= w * 10000; | ||
237 | if (w >= 10) STR_BUFINT_R(w, 10, 10) | ||
238 | *p++ = (char)('0'+w); | ||
239 | } | ||
240 | STR_BUFINT_R(v, 23, 1000) | ||
241 | dig7: STR_BUFINT_R(v, 12, 100) | ||
242 | dig6: STR_BUFINT_R(v, 10, 10) | ||
243 | dig5: *p++ = (char)('0'+v); | ||
244 | } | ||
245 | STR_BUFINT_R(u, 23, 1000) | ||
246 | dig3: STR_BUFINT_R(u, 12, 100) | ||
247 | dig2: STR_BUFINT_R(u, 10, 10) | ||
248 | dig1: *p++ = (char)('0'+u); | ||
249 | return p; | ||
250 | } | ||
251 | |||
252 | /* Print pointer to buffer. */ | ||
253 | char * LJ_FASTCALL lj_str_bufptr(char *p, const void *v) | ||
254 | { | ||
255 | ptrdiff_t x = (ptrdiff_t)v; | ||
256 | MSize i, n = LJ_STR_PTRBUF; | ||
257 | if (x == 0) { | ||
258 | *p++ = 'N'; *p++ = 'U'; *p++ = 'L'; *p++ = 'L'; | ||
259 | return p; | ||
260 | } | ||
261 | #if LJ_64 | ||
262 | /* Shorten output for 64 bit pointers. */ | ||
263 | n = 2+2*4+((x >> 32) ? 2+2*(lj_fls((uint32_t)(x >> 32))>>3) : 0); | ||
264 | #endif | ||
265 | p[0] = '0'; | ||
266 | p[1] = 'x'; | ||
267 | for (i = n-1; i >= 2; i--, x >>= 4) | ||
268 | p[i] = "0123456789abcdef"[(x & 15)]; | ||
269 | return p+n; | ||
270 | } | ||
271 | |||
272 | /* Print TValue to buffer (only for numbers) and return pointer to start. */ | ||
273 | const char *lj_str_buftv(char *buf, cTValue *o, MSize *lenp) | ||
274 | { | ||
275 | if (tvisstr(o)) { | ||
276 | *lenp = strV(o)->len; | ||
277 | return strVdata(o); | ||
278 | } else if (tvisint(o)) { | ||
279 | *lenp = (MSize)(lj_str_bufint(buf, intV(o)) - buf); | ||
280 | return buf; | ||
281 | } else if (tvisnum(o)) { | ||
282 | *lenp = (MSize)(lj_str_bufnum(buf, o) - buf); | ||
283 | return buf; | ||
284 | } else { | ||
285 | return NULL; | ||
286 | } | ||
287 | } | ||
288 | |||
289 | /* Convert number to string. */ | ||
290 | GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np) | ||
291 | { | ||
292 | char buf[LJ_STR_NUMBUF]; | ||
293 | MSize len = (MSize)(lj_str_bufnum(buf, (TValue *)np) - buf); | ||
294 | return lj_str_new(L, buf, len); | ||
295 | } | ||
296 | |||
297 | /* Convert integer to string. */ | ||
298 | GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k) | ||
299 | { | ||
300 | char buf[LJ_STR_INTBUF]; | ||
301 | MSize len = (MSize)(lj_str_bufint(buf, k) - buf); | ||
302 | return lj_str_new(L, buf, len); | ||
303 | } | ||
304 | |||
305 | GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o) | ||
306 | { | ||
307 | return tvisint(o) ? lj_str_fromint(L, intV(o)) : lj_str_fromnum(L, &o->n); | ||
308 | } | ||
309 | |||
310 | /* Convert char value to string. */ | ||
311 | GCstr * LJ_FASTCALL lj_str_fromchar(lua_State *L, int c) | ||
312 | { | ||
313 | char buf[1]; | ||
314 | buf[0] = c; | ||
315 | return lj_str_new(L, buf, 1); | ||
316 | } | ||
317 | |||