In theory multibyte decimal_points are possible, but * Lua CJSON only supports UTF-8 and known locales only have * single byte decimal points ([.,]). * * localconv() may not be thread safe (=>crash), and nl_langinfo() is * not supported on some platforms. Use sprintf() instead - if the * locale does change, at least Lua CJSON won't crash. */
| 50 | * not supported on some platforms. Use sprintf() instead - if the |
| 51 | * locale does change, at least Lua CJSON won't crash. */ |
| 52 | static void fpconv_update_locale() |
| 53 | { |
| 54 | char buf[8]; |
| 55 | |
| 56 | snprintf(buf, sizeof(buf), "%g", 0.5); |
| 57 | |
| 58 | /* Failing this test might imply the platform has a buggy dtoa |
| 59 | * implementation or wide characters */ |
| 60 | if (buf[0] != '0' || buf[2] != '5' || buf[3] != 0) { |
| 61 | fprintf(stderr, "Error: wide characters found or printf() bug."); |
| 62 | abort(); |
| 63 | } |
| 64 | |
| 65 | locale_decimal_point = buf[1]; |
| 66 | } |
| 67 | |
| 68 | /* Check for a valid number character: [-+0-9a-yA-Y.] |
| 69 | * Eg: -0.6e+5, infinity, 0xF0.F0pF0 |
no test coverage detected