diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-03 13:02:41 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2020-07-03 13:02:41 -0300 |
commit | 0280407fc54f9b6225139c5ac27326f98f0cf043 (patch) | |
tree | 74a7c1f7cde9120d67e17ce40602b4cfd7498d80 /lobject.c | |
parent | ae809e9fd132ab867741a6a777450f9bc0d49be4 (diff) | |
download | lua-0280407fc54f9b6225139c5ac27326f98f0cf043.tar.gz lua-0280407fc54f9b6225139c5ac27326f98f0cf043.tar.bz2 lua-0280407fc54f9b6225139c5ac27326f98f0cf043.zip |
Details
Comments in makefile and function 'l_str2d'.
Diffstat (limited to 'lobject.c')
-rw-r--r-- | lobject.c | 21 |
1 files changed, 13 insertions, 8 deletions
@@ -220,32 +220,37 @@ static lua_Number lua_strx2number (const char *s, char **endptr) { | |||
220 | #define L_MAXLENNUM 200 | 220 | #define L_MAXLENNUM 200 |
221 | #endif | 221 | #endif |
222 | 222 | ||
223 | /* | ||
224 | ** Convert string 's' to a Lua number (put in 'result'). Return NULL on | ||
225 | ** fail or the address of the ending '\0' on success. ('mode' == 'x') | ||
226 | ** means a hexadecimal numeral. | ||
227 | */ | ||
223 | static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { | 228 | static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { |
224 | char *endptr; | 229 | char *endptr; |
225 | *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ | 230 | *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ |
226 | : lua_str2number(s, &endptr); | 231 | : lua_str2number(s, &endptr); |
227 | if (endptr == s) return NULL; /* nothing recognized? */ | 232 | if (endptr == s) return NULL; /* nothing recognized? */ |
228 | while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ | 233 | while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ |
229 | return (*endptr == '\0') ? endptr : NULL; /* OK if no trailing characters */ | 234 | return (*endptr == '\0') ? endptr : NULL; /* OK iff no trailing chars */ |
230 | } | 235 | } |
231 | 236 | ||
232 | 237 | ||
233 | /* | 238 | /* |
234 | ** Convert string 's' to a Lua number (put in 'result'). Return NULL | 239 | ** Convert string 's' to a Lua number (put in 'result') handling the |
235 | ** on fail or the address of the ending '\0' on success. | 240 | ** current locale. |
236 | ** 'pmode' points to (and 'mode' contains) special things in the string: | ||
237 | ** - 'x'/'X' means a hexadecimal numeral | ||
238 | ** - 'n'/'N' means 'inf' or 'nan' (which should be rejected) | ||
239 | ** - '.' just optimizes the search for the common case (nothing special) | ||
240 | ** This function accepts both the current locale or a dot as the radix | 241 | ** This function accepts both the current locale or a dot as the radix |
241 | ** mark. If the conversion fails, it may mean number has a dot but | 242 | ** mark. If the conversion fails, it may mean number has a dot but |
242 | ** locale accepts something else. In that case, the code copies 's' | 243 | ** locale accepts something else. In that case, the code copies 's' |
243 | ** to a buffer (because 's' is read-only), changes the dot to the | 244 | ** to a buffer (because 's' is read-only), changes the dot to the |
244 | ** current locale radix mark, and tries to convert again. | 245 | ** current locale radix mark, and tries to convert again. |
246 | ** The variable 'mode' checks for special characters in the string: | ||
247 | ** - 'n' means 'inf' or 'nan' (which should be rejected) | ||
248 | ** - 'x' means a hexadecimal numeral | ||
249 | ** - '.' just optimizes the search for the common case (no special chars) | ||
245 | */ | 250 | */ |
246 | static const char *l_str2d (const char *s, lua_Number *result) { | 251 | static const char *l_str2d (const char *s, lua_Number *result) { |
247 | const char *endptr; | 252 | const char *endptr; |
248 | const char *pmode = strpbrk(s, ".xXnN"); | 253 | const char *pmode = strpbrk(s, ".xXnN"); /* look for special chars */ |
249 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; | 254 | int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; |
250 | if (mode == 'n') /* reject 'inf' and 'nan' */ | 255 | if (mode == 'n') /* reject 'inf' and 'nan' */ |
251 | return NULL; | 256 | return NULL; |