diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-12-07 13:33:27 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-12-07 13:33:27 -0200 |
commit | 16fd4abaf618fb37ade221cbc64399c519685854 (patch) | |
tree | c28206f582ee7f8267098f39f3962036ec09528d | |
parent | f26b85c5b7740d2a185998a155e1323bac86dc13 (diff) | |
download | lua-16fd4abaf618fb37ade221cbc64399c519685854.tar.gz lua-16fd4abaf618fb37ade221cbc64399c519685854.tar.bz2 lua-16fd4abaf618fb37ade221cbc64399c519685854.zip |
corrects decimal point to follow current locale
-rw-r--r-- | llex.c | 17 | ||||
-rw-r--r-- | llex.h | 3 |
2 files changed, 17 insertions, 3 deletions
@@ -1,11 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 2.12 2005/05/17 19:49:15 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 2.13 2005/11/08 19:45:14 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
7 | 7 | ||
8 | #include <ctype.h> | 8 | #include <ctype.h> |
9 | #include <locale.h> | ||
9 | #include <string.h> | 10 | #include <string.h> |
10 | 11 | ||
11 | #define llex_c | 12 | #define llex_c |
@@ -134,6 +135,8 @@ static void inclinenumber (LexState *ls) { | |||
134 | 135 | ||
135 | 136 | ||
136 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { | 137 | void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) { |
138 | struct lconv *cv = localeconv(); | ||
139 | ls->decpoint = (cv ? cv->decimal_point[0] : '.'); | ||
137 | ls->L = L; | 140 | ls->L = L; |
138 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ | 141 | ls->lookahead.token = TK_EOS; /* no look-ahead token */ |
139 | ls->z = z; | 142 | ls->z = z; |
@@ -163,6 +166,13 @@ static int check_next (LexState *ls, const char *set) { | |||
163 | } | 166 | } |
164 | 167 | ||
165 | 168 | ||
169 | static void correctbuff (LexState *ls, char from, char to) { | ||
170 | int n = luaZ_bufflen(ls->buff); | ||
171 | char *p = luaZ_buffer(ls->buff); | ||
172 | while (n--) | ||
173 | if (p[n] == from) p[n] = to; | ||
174 | } | ||
175 | |||
166 | 176 | ||
167 | /* LUA_NUMBER */ | 177 | /* LUA_NUMBER */ |
168 | static void read_numeral (LexState *ls, SemInfo *seminfo) { | 178 | static void read_numeral (LexState *ls, SemInfo *seminfo) { |
@@ -177,8 +187,11 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { | |||
177 | } | 187 | } |
178 | } | 188 | } |
179 | save(ls, '\0'); | 189 | save(ls, '\0'); |
180 | if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) | 190 | correctbuff(ls, '.', ls->decpoint); /* follow locale for decimal point */ |
191 | if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { | ||
192 | correctbuff(ls, ls->decpoint, '.'); /* undo change */ | ||
181 | luaX_lexerror(ls, "malformed number", TK_NUMBER); | 193 | luaX_lexerror(ls, "malformed number", TK_NUMBER); |
194 | } | ||
182 | } | 195 | } |
183 | 196 | ||
184 | 197 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.h,v 1.54 2005/04/25 19:24:10 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.55 2005/06/06 13:30:25 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -63,6 +63,7 @@ typedef struct LexState { | |||
63 | ZIO *z; /* input stream */ | 63 | ZIO *z; /* input stream */ |
64 | Mbuffer *buff; /* buffer for tokens */ | 64 | Mbuffer *buff; /* buffer for tokens */ |
65 | TString *source; /* current source name */ | 65 | TString *source; /* current source name */ |
66 | char decpoint; /* locale decimal point */ | ||
66 | } LexState; | 67 | } LexState; |
67 | 68 | ||
68 | 69 | ||