Skip to content

Commit d70c1ea

Browse files
committed
Bump version & amalgamate
1 parent a10efc8 commit d70c1ea

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

amalgamate.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
OUTPUT_PATH = "single_include/jsonh_cpp_amalgamated.hpp"
44

55
HEADER = "// JsonhCpp (JSON for Humans)
6-
// Version: 4.11
6+
// Version: 4.12
77
// Link: https://github.com/jsonh-org/JsonhCpp
88
// License: MIT"
99

single_include/jsonh_cpp_amalgamated.hpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// JsonhCpp (JSON for Humans)
2-
// Version: 4.11
2+
// Version: 4.12
33
// Link: https://github.com/jsonh-org/JsonhCpp
44
// License: MIT
55

@@ -30713,48 +30713,58 @@ class jsonh_reader : utf8_reader {
3071330713
// Read base
3071430714
std::string base_digits = "0123456789";
3071530715
bool has_base_specifier = false;
30716+
bool has_leading_zero = false;
3071630717
if (read_one("0")) {
3071730718
number_builder += '0';
30719+
has_leading_zero = true;
3071830720

3071930721
std::optional<std::string> hex_base_char = read_any({ "x", "X" });
3072030722
if (hex_base_char) {
3072130723
number_builder += hex_base_char.value();
3072230724
base_digits = "0123456789abcdef";
3072330725
has_base_specifier = true;
30726+
has_leading_zero = false;
3072430727
}
3072530728
else {
3072630729
std::optional<std::string> binary_base_char = read_any({ "b", "B" });
3072730730
if (binary_base_char) {
3072830731
number_builder += binary_base_char.value();
3072930732
base_digits = "01";
3073030733
has_base_specifier = true;
30734+
has_leading_zero = false;
3073130735
}
3073230736
else {
3073330737
std::optional<std::string> octal_base_char = read_any({ "o", "O" });
3073430738
if (octal_base_char) {
3073530739
number_builder += octal_base_char.value();
3073630740
base_digits = "01234567";
3073730741
has_base_specifier = true;
30742+
has_leading_zero = false;
3073830743
}
3073930744
}
3074030745
}
3074130746
}
3074230747

3074330748
// Read main number
30744-
nonstd::expected<void, std::string> main_result = read_number_no_exponent(number_builder, base_digits, has_base_specifier);
30749+
nonstd::expected<void, std::string> main_result = read_number_no_exponent(number_builder, base_digits, has_base_specifier, has_leading_zero);
3074530750
if (!main_result) {
3074630751
return nonstd::unexpected<std::string>(main_result.error());
3074730752
}
3074830753

30749-
// Hexadecimal exponent
30754+
// Possible hexadecimal exponent
3075030755
if (number_builder.back() == 'e' || number_builder.back() == 'E') {
30751-
// Read sign
30756+
// Read sign (mandatory)
3075230757
std::optional<std::string> exponent_sign = read_any({ "+", "-" });
3075330758
if (exponent_sign) {
3075430759
number_builder += exponent_sign.value();
3075530760

30761+
// Missing digit between base specifier and exponent (e.g. `0xe+`)
30762+
if (has_base_specifier && number_builder.size() == 4) {
30763+
return nonstd::unexpected<std::string>("Missing digit between base specifier and exponent");
30764+
}
30765+
3075630766
// Read exponent number
30757-
nonstd::expected<void, std::string> exponent_result = read_number_no_exponent(number_builder, base_digits, has_base_specifier);
30767+
nonstd::expected<void, std::string> exponent_result = read_number_no_exponent(number_builder, base_digits);
3075830768
if (!exponent_result) {
3075930769
return nonstd::unexpected<std::string>(exponent_result.error());
3076030770
}
@@ -30773,7 +30783,7 @@ class jsonh_reader : utf8_reader {
3077330783
}
3077430784

3077530785
// Read exponent number
30776-
nonstd::expected<void, std::string> exponent_result = read_number_no_exponent(number_builder, base_digits, has_base_specifier);
30786+
nonstd::expected<void, std::string> exponent_result = read_number_no_exponent(number_builder, base_digits);
3077730787
if (!exponent_result) {
3077830788
return nonstd::unexpected<std::string>(exponent_result.error());
3077930789
}
@@ -30783,7 +30793,7 @@ class jsonh_reader : utf8_reader {
3078330793
// End of number
3078430794
return jsonh_token(json_token_type::number, number_builder);
3078530795
}
30786-
nonstd::expected<void, std::string> read_number_no_exponent(std::string& number_builder, std::string_view base_digits, bool has_base_specifier) noexcept {
30796+
nonstd::expected<void, std::string> read_number_no_exponent(std::string& number_builder, std::string_view base_digits, bool has_base_specifier = false, bool has_leading_zero = false) noexcept {
3078730797
// Leading underscore
3078830798
if (!has_base_specifier && peek() == "_") {
3078930799
return nonstd::unexpected<std::string>("Leading `_` in number");
@@ -30793,7 +30803,7 @@ class jsonh_reader : utf8_reader {
3079330803
bool is_empty = true;
3079430804

3079530805
// Leading zero (not base specifier)
30796-
if (!has_base_specifier && number_builder.size() >= 1 && number_builder.back() == '0') {
30806+
if (has_leading_zero) {
3079730807
is_empty = false;
3079830808
}
3079930809

0 commit comments

Comments
 (0)