diff options
author | Mike Pall <mike> | 2012-08-25 23:02:29 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2012-08-25 23:02:29 +0200 |
commit | 4c882fe71406a923f07c8e9a0b9189036e0ba386 (patch) | |
tree | 22aa3995b5bdc2fce05ba17488799e67abc635ba /src/lj_strscan.h | |
parent | 653facd0d5c1a4f7eae43eefbf8148f57e28e606 (diff) | |
download | luajit-4c882fe71406a923f07c8e9a0b9189036e0ba386.tar.gz luajit-4c882fe71406a923f07c8e9a0b9189036e0ba386.tar.bz2 luajit-4c882fe71406a923f07c8e9a0b9189036e0ba386.zip |
Replace strtod() with builtin string to number conversion.
Diffstat (limited to 'src/lj_strscan.h')
-rw-r--r-- | src/lj_strscan.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lj_strscan.h b/src/lj_strscan.h new file mode 100644 index 00000000..da5bd095 --- /dev/null +++ b/src/lj_strscan.h | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | ** String scanning. | ||
3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_STRSCAN_H | ||
7 | #define _LJ_STRSCAN_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | |||
11 | /* Options for accepted/returned formats. */ | ||
12 | #define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */ | ||
13 | #define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */ | ||
14 | #define STRSCAN_OPT_IMAG 0x04 | ||
15 | #define STRSCAN_OPT_LL 0x08 | ||
16 | #define STRSCAN_OPT_C 0x10 | ||
17 | |||
18 | /* Returned format. */ | ||
19 | typedef enum { | ||
20 | STRSCAN_ERROR, | ||
21 | STRSCAN_NUM, STRSCAN_IMAG, | ||
22 | STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64, | ||
23 | } StrScanFmt; | ||
24 | |||
25 | LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt); | ||
26 | LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o); | ||
27 | #if LJ_DUALNUM | ||
28 | LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o); | ||
29 | #else | ||
30 | #define lj_strscan_number(s, o) lj_strscan_num((s), (o)) | ||
31 | #endif | ||
32 | |||
33 | /* Check for number or convert string to number/int in-place (!). */ | ||
34 | static LJ_AINLINE int lj_strscan_numberobj(TValue *o) | ||
35 | { | ||
36 | return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o)); | ||
37 | } | ||
38 | |||
39 | #endif | ||