diff options
Diffstat (limited to 'lobject.c')
| -rw-r--r-- | lobject.c | 31 |
1 files changed, 14 insertions, 17 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 1.21 1999/09/06 13:55:09 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 1.22 1999/09/06 20:19:22 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -91,37 +91,34 @@ static double expten (unsigned int e) { | |||
| 91 | int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ | 91 | int luaO_str2d (const char *s, real *result) { /* LUA_NUMBER */ |
| 92 | double a = 0.0; | 92 | double a = 0.0; |
| 93 | int point = 0; /* number of decimal digits */ | 93 | int point = 0; /* number of decimal digits */ |
| 94 | int sig = 1; | 94 | int sig; |
| 95 | int valid = 0; /* check whether number has at least one valid digit */ | ||
| 96 | while (isspace((unsigned char)*s)) s++; | 95 | while (isspace((unsigned char)*s)) s++; |
| 97 | if (*s == '-') { | 96 | sig = 1; |
| 98 | s++; | 97 | switch (*s) { |
| 99 | sig = -1; | 98 | case '-': sig = -1; /* go through */ |
| 99 | case '+': s++; | ||
| 100 | } | 100 | } |
| 101 | else if (*s == '+') s++; | 101 | if (! (isdigit((unsigned char)*s) || |
| 102 | while (isdigit((unsigned char)*s)) { | 102 | (*s == '.' && isdigit((unsigned char)*(s+1))))) |
| 103 | return 0; /* not (at least one digit before or after the point) */ | ||
| 104 | while (isdigit((unsigned char)*s)) | ||
| 103 | a = 10.0*a + (*(s++)-'0'); | 105 | a = 10.0*a + (*(s++)-'0'); |
| 104 | valid = 1; | ||
| 105 | } | ||
| 106 | if (*s == '.') { | 106 | if (*s == '.') { |
| 107 | s++; | 107 | s++; |
| 108 | while (isdigit((unsigned char)*s)) { | 108 | while (isdigit((unsigned char)*s)) { |
| 109 | a = 10.0*a + (*(s++)-'0'); | 109 | a = 10.0*a + (*(s++)-'0'); |
| 110 | point++; | 110 | point++; |
| 111 | valid = 1; | ||
| 112 | } | 111 | } |
| 113 | } | 112 | } |
| 114 | if (!valid) return 0; | ||
| 115 | a *= sig; | 113 | a *= sig; |
| 116 | if (toupper((unsigned char)*s) == 'E') { | 114 | if (toupper((unsigned char)*s) == 'E') { |
| 117 | int e = 0; | 115 | int e = 0; |
| 118 | sig = 1; | ||
| 119 | s++; | 116 | s++; |
| 120 | if (*s == '-') { | 117 | sig = 1; |
| 121 | s++; | 118 | switch (*s) { |
| 122 | sig = -1; | 119 | case '-': sig = -1; /* go through */ |
| 120 | case '+': s++; | ||
| 123 | } | 121 | } |
| 124 | else if (*s == '+') s++; | ||
| 125 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ | 122 | if (!isdigit((unsigned char)*s)) return 0; /* no digit in the exponent? */ |
| 126 | do { | 123 | do { |
| 127 | e = 10*e + (*(s++)-'0'); | 124 | e = 10*e + (*(s++)-'0'); |
