11// JsonhCpp (JSON for Humans)
2- // Version: 4.2
2+ // Version: 4.3
33// Link: https://github.com/jsonh-org/JsonhCpp
44// License: MIT
55
@@ -29159,7 +29159,7 @@ class jsonh_number_parser final {
2915929159 std::string base_digits = "0123456789";
2916029160 // Hexadecimal
2916129161 if (jsonh_number.starts_with("0x") || jsonh_number.starts_with("0X")) {
29162- base_digits = "0123456789ABCDEFabcdef ";
29162+ base_digits = "0123456789abcdef ";
2916329163 jsonh_number.erase(0, 2);
2916429164 }
2916529165 // Binary
@@ -29185,8 +29185,11 @@ class jsonh_number_parser final {
2918529185 /// Converts a fractional number with an exponent (e.g. <c>12.3e4.5</c>) from the given base (e.g. <c>01234567</c>) to a base-10 real.
2918629186 /// </summary>
2918729187 static nonstd::expected<long double, std::string> parse_fractional_number_with_exponent(std::string_view digits, std::string_view base_digits) noexcept {
29188- // Find exponent
29189- size_t exponent_index = digits.find_first_of("eE");
29188+ // Find exponent (unless hexadecimal)
29189+ size_t exponent_index = std::string::npos;
29190+ if (base_digits.find("e") == std::string::npos) {
29191+ exponent_index = digits.find_first_of("eE");
29192+ }
2919029193 // If no exponent then normalize real
2919129194 if (exponent_index == std::string::npos) {
2919229195 return parse_fractional_number(digits, base_digits);
@@ -29256,7 +29259,7 @@ class jsonh_number_parser final {
2925629259 }
2925729260
2925829261 // Get sign
29259- size_t sign = 1;
29262+ int sign = 1;
2926029263 if (digits.starts_with('-')) {
2926129264 sign = -1;
2926229265 digits = digits.substr(1);
@@ -29271,7 +29274,7 @@ class jsonh_number_parser final {
2927129274 for (size_t index = 0; index < digits.size(); index++) {
2927229275 // Get current digit
2927329276 char digit_char = digits[index];
29274- size_t digit_int = base_digits.find(digit_char);
29277+ size_t digit_int = base_digits.find((char)std::tolower( digit_char) );
2927529278
2927629279 // Ensure digit is valid
2927729280 if (digit_int == std::string::npos) {
@@ -30460,7 +30463,7 @@ class jsonh_reader : utf8_reader {
3046030463 std::optional<std::string> hex_base_char = read_any({ "x", "X" });
3046130464 if (hex_base_char) {
3046230465 number_builder += hex_base_char.value();
30463- base_digits = "0123456789ABCDEFabcdef ";
30466+ base_digits = "0123456789abcdef ";
3046430467 }
3046530468 else {
3046630469 std::optional<std::string> binary_base_char = read_any({ "b", "B" });
@@ -30518,7 +30521,7 @@ class jsonh_reader : utf8_reader {
3051830521 }
3051930522
3052030523 // Digit
30521- if (base_digits.find(next.value()) != std::string::npos) {
30524+ if (base_digits.find(to_lower( next.value().data() )) != std::string::npos) {
3052230525 read();
3052330526 number_builder += next.value();
3052430527 }
@@ -30853,6 +30856,13 @@ class jsonh_reader : utf8_reader {
3085330856 static bool is_utf16_high_surrogate(unsigned int code_point) noexcept {
3085430857 return code_point >= 0xD800 && code_point <= 0xDBFF;
3085530858 }
30859+ static std::string to_lower(const char* string) noexcept {
30860+ std::string result(string);
30861+ for (char& next : result) {
30862+ next = std::tolower(next);
30863+ }
30864+ return result;
30865+ }
3085630866};
3085730867
3085830868}
0 commit comments