Skip to content

Commit cb2fe91

Browse files
authored
fix(ini): Support plus sign prefix in INI integer parse (#2576)
1 parent 4c065e4 commit cb2fe91

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • Core/GameEngine/Source/Common/INI

Core/GameEngine/Source/Common/INI/INI.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,8 +1618,17 @@ void INI::initFromINIMulti( void *what, const MultiIniFieldParse& parseTableList
16181618
template <typename Type>
16191619
Type scanType(std::string_view token)
16201620
{
1621-
// TheSuperHackers @info std::from_chars cannot parse "-1" as uint32 so the result needs to be int64 for integers.
1622-
std::conditional_t<std::is_integral_v<Type>, Int64, Real> result{};
1621+
DEBUG_ASSERTCRASH(!token.empty(), ("token is not expected to be empty"));
1622+
1623+
// Unlike sscanf, std::from_chars cannot parse "+".
1624+
// Consume the plus symbol to accommodate custom ini files that have numbers prefixed with a plus.
1625+
if (token[0] == '+')
1626+
{
1627+
token.remove_prefix(1);
1628+
}
1629+
1630+
// Unlike sscanf, std::from_chars cannot parse "-" as unsigned integer.
1631+
std::conditional_t<std::is_integral_v<Type>, Int64, Type> result{};
16231632
const auto [ptr, ec] = std::from_chars(token.data(), token.data() + token.size(), result);
16241633

16251634
if (ec != std::errc{})

0 commit comments

Comments
 (0)