mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
feat: parse hex int upper/lowercase
This commit is contained in:
@@ -292,7 +292,7 @@ parse_hex_integer(location& loc, const context<TC>& ctx)
|
|||||||
if( ! reg.is_ok())
|
if( ! reg.is_ok())
|
||||||
{
|
{
|
||||||
return err(make_syntax_error("toml::parse_hex_integer: "
|
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));
|
syntax::hex_int(spec), loc));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,6 +320,14 @@ parse_hex_integer(location& loc, const context<TC>& ctx)
|
|||||||
// 0x0000_0000 becomes empty.
|
// 0x0000_0000 becomes empty.
|
||||||
if(str.empty()) { str = "0"; }
|
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);
|
const auto val = TC::parse_int(str, source_location(region(loc)), 16);
|
||||||
if(val.is_ok())
|
if(val.is_ok())
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user