mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-26 14:20:05 +00:00
feat: parse hex int upper/lowercase
This commit is contained in:
parent
acd6ed9a1e
commit
49b373d4f5
@ -292,7 +292,7 @@ parse_hex_integer(location& loc, const context<TC>& 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<TC>& 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<int>(c)) != 0; }) == str.end();
|
||||
const auto upper_found = std::find_if(str.begin(), str.end(),
|
||||
[](const char c) { return std::isupper(static_cast<int>(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())
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user