🔨 added code for locale-independent number parsing

This commit is contained in:
Niels Lohmann 2017-03-26 18:12:58 +02:00
parent 06e2a291b1
commit 3425527970
No known key found for this signature in database
GPG key ID: 7F3CEA63AE251B69
2 changed files with 21 additions and 11 deletions

View file

@ -1,7 +0,0 @@
- test/test-class_parser
- 617 failed
- test/test-regression
- 11 failed
- test/test-testsuites
- 43 failed

View file

@ -10517,12 +10517,13 @@ class basic_json
} }
explicit lexer(std::istream& i) explicit lexer(std::istream& i)
// : ia(new input_stream_adapter(i)) : ia(new cached_input_stream_adapter(i)),
: ia(new cached_input_stream_adapter(i)) decimal_point_char(get_decimal_point())
{} {}
lexer(const char* buff, const size_t len) lexer(const char* buff, const size_t len)
: ia(new input_buffer_adapter(buff, len)) : ia(new input_buffer_adapter(buff, len)),
decimal_point_char(get_decimal_point())
{} {}
~lexer() ~lexer()
@ -10536,6 +10537,18 @@ class basic_json
lexer operator=(const lexer&) = delete; lexer operator=(const lexer&) = delete;
private: private:
/////////////////////
// locales
/////////////////////
/// return the locale-dependent decimal point
static char get_decimal_point() noexcept
{
const auto loc = localeconv();
assert(loc != nullptr);
return (loc->decimal_point == nullptr) ? '.' : loc->decimal_point[0];
}
///////////////////// /////////////////////
// scan functions // scan functions
///////////////////// /////////////////////
@ -10815,7 +10828,8 @@ class basic_json
return token_type::parse_error; return token_type::parse_error;
} }
add(current); // add current character and fix decimal point
add((state == 4) ? decimal_point_char : current);
get(); get();
old_state = state; old_state = state;
state = lookup[state][static_cast<unsigned char>(current)]; state = lookup[state][static_cast<unsigned char>(current)];
@ -11103,6 +11117,9 @@ class basic_json
long long value_integer = 0; long long value_integer = 0;
unsigned long long value_unsigned = 0; unsigned long long value_unsigned = 0;
double value_float = 0; double value_float = 0;
// the decimal point
const char decimal_point_char = '\0';
}; };
/*! /*!