diff options
Diffstat (limited to 'src/lj_str.c')
-rw-r--r-- | src/lj_str.c | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/src/lj_str.c b/src/lj_str.c index 7bf4848a..1060ec6d 100644 --- a/src/lj_str.c +++ b/src/lj_str.c | |||
@@ -169,85 +169,6 @@ void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s) | |||
169 | 169 | ||
170 | /* -- Type conversions ---------------------------------------------------- */ | 170 | /* -- Type conversions ---------------------------------------------------- */ |
171 | 171 | ||
172 | /* Convert string object to number. */ | ||
173 | int LJ_FASTCALL lj_str_tonum(GCstr *str, TValue *n) | ||
174 | { | ||
175 | int ok = lj_str_numconv(strdata(str), n); | ||
176 | if (ok && tvisint(n)) | ||
177 | setnumV(n, (lua_Number)intV(n)); | ||
178 | return ok; | ||
179 | } | ||
180 | |||
181 | int LJ_FASTCALL lj_str_tonumber(GCstr *str, TValue *n) | ||
182 | { | ||
183 | return lj_str_numconv(strdata(str), n); | ||
184 | } | ||
185 | |||
186 | /* Convert string to number. */ | ||
187 | int LJ_FASTCALL lj_str_numconv(const char *s, TValue *n) | ||
188 | { | ||
189 | #if LJ_DUALNUM | ||
190 | int sign = 1; | ||
191 | #else | ||
192 | lua_Number sign = 1; | ||
193 | #endif | ||
194 | const uint8_t *p = (const uint8_t *)s; | ||
195 | while (lj_char_isspace(*p)) p++; | ||
196 | if (*p == '-') { p++; sign = -1; } else if (*p == '+') { p++; } | ||
197 | if ((uint32_t)(*p - '0') < 10) { | ||
198 | uint32_t k = (uint32_t)(*p++ - '0'); | ||
199 | if (k == 0 && ((*p & ~0x20) == 'X')) { | ||
200 | p++; | ||
201 | if (!lj_char_isxdigit(*p)) | ||
202 | return 0; /* Don't accept '0x' without hex digits. */ | ||
203 | do { | ||
204 | if (k >= 0x10000000u) goto parsedbl; | ||
205 | k = (k << 4) + (*p & 15u); | ||
206 | if (!lj_char_isdigit(*p)) k += 9; | ||
207 | p++; | ||
208 | } while (lj_char_isxdigit(*p)); | ||
209 | } else { | ||
210 | while ((uint32_t)(*p - '0') < 10) { | ||
211 | if (LJ_UNLIKELY(k >= 429496729) && (k != 429496729 || *p > '5')) | ||
212 | goto parsedbl; | ||
213 | k = k * 10u + (uint32_t)(*p++ - '0'); | ||
214 | } | ||
215 | } | ||
216 | while (LJ_UNLIKELY(lj_char_isspace(*p))) p++; | ||
217 | if (LJ_LIKELY(*p == '\0')) { | ||
218 | #if LJ_DUALNUM | ||
219 | if (sign == 1) { | ||
220 | if (k < 0x80000000u) { | ||
221 | setintV(n, (int32_t)k); | ||
222 | return 1; | ||
223 | } | ||
224 | } else if (k <= 0x80000000u) { | ||
225 | setintV(n, -(int32_t)k); | ||
226 | return 1; | ||
227 | } | ||
228 | #endif | ||
229 | setnumV(n, sign * (lua_Number)k); | ||
230 | return 1; | ||
231 | } | ||
232 | } | ||
233 | parsedbl: | ||
234 | { | ||
235 | TValue tv; | ||
236 | char *endptr; | ||
237 | setnumV(&tv, lua_str2number(s, &endptr)); | ||
238 | if (endptr == s) return 0; /* Conversion failed. */ | ||
239 | if (LJ_UNLIKELY(*endptr != '\0')) { | ||
240 | while (lj_char_isspace((uint8_t)*endptr)) endptr++; | ||
241 | if (*endptr != '\0') return 0; /* Invalid trailing characters? */ | ||
242 | } | ||
243 | if (LJ_LIKELY(!tvisnan(&tv))) | ||
244 | setnumV(n, numV(&tv)); | ||
245 | else | ||
246 | setnanV(n); /* Canonicalize injected NaNs. */ | ||
247 | return 1; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | /* Print number to buffer. Canonicalizes non-finite values. */ | 172 | /* Print number to buffer. Canonicalizes non-finite values. */ |
252 | size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o) | 173 | size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o) |
253 | { | 174 | { |