From 49b373d4f5dd65b44dbdede31c499f8e465721e0 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 14 Jul 2024 15:12:02 +0900 Subject: [PATCH] feat: parse hex int upper/lowercase --- include/toml11/parser.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/toml11/parser.hpp b/include/toml11/parser.hpp index 8b60810..dd7aba9 100644 --- a/include/toml11/parser.hpp +++ b/include/toml11/parser.hpp @@ -292,7 +292,7 @@ parse_hex_integer(location& loc, const context& ctx) if( ! reg.is_ok()) { return err(make_syntax_error("toml::parse_hex_integer: " - "invalid integer: hex_int must be like: 0xC0FFEE, 0xDEAD_BEEF", + "invalid integer: hex_int must be like: 0xC0FFEE, 0xdead_beef", syntax::hex_int(spec), loc)); } @@ -320,6 +320,14 @@ parse_hex_integer(location& loc, const context& ctx) // 0x0000_0000 becomes empty. if(str.empty()) { str = "0"; } + // prefix zero and _ is removed. check if it uses upper/lower case. + // if both upper and lower case letters are found, set upper=true. + const auto lower_not_found = std::find_if(str.begin(), str.end(), + [](const char c) { return std::islower(static_cast(c)) != 0; }) == str.end(); + const auto upper_found = std::find_if(str.begin(), str.end(), + [](const char c) { return std::isupper(static_cast(c)) != 0; }) != str.end(); + fmt.uppercase = lower_not_found || upper_found; + const auto val = TC::parse_int(str, source_location(region(loc)), 16); if(val.is_ok()) {