diff --git a/src/util/config/config.cpp b/src/util/config/config.cpp index be4689aa..80136501 100644 --- a/src/util/config/config.cpp +++ b/src/util/config/config.cpp @@ -755,6 +755,66 @@ namespace dxvk { } + bool Config::parseOptionValue( + const std::string& value, + float& result) { + if (value.size() == 0) + return false; + + // Parse sign + size_t pos = 0; + bool negate = false; + + if (value[0] == '-') { + negate = true; + pos += 1; + } + + // Parse integer part + uint64_t intPart = 0; + + if (value[pos] == '.') + return false; + + while (pos < value.size()) { + if (value[pos] == '.') { + if (++pos == value.size()) + return false; + break; + } + + if (value[pos] < '0' || value[pos] > '9') + return false; + + intPart *= 10; + intPart += value[pos] - '0'; + pos += 1; + } + + // Parse fractional part + uint64_t fractPart = 0; + uint64_t fractDivisor = 1; + + while (pos < value.size()) { + if (value[pos] < '0' || value[pos] > '9') + return false; + + fractDivisor *= 10; + fractPart *= 10; + fractPart += value[pos] - '0'; + pos += 1; + } + + // Compute final number, not super accurate but this should do + result = float((double(fractPart) / double(fractDivisor)) + double(intPart)); + + if (negate) + result = -result; + + return true; + } + + bool Config::parseOptionValue( const std::string& value, Tristate& result) { diff --git a/src/util/config/config.h b/src/util/config/config.h index f947272c..eb849254 100644 --- a/src/util/config/config.h +++ b/src/util/config/config.h @@ -123,6 +123,10 @@ namespace dxvk { const std::string& value, int32_t& result); + static bool parseOptionValue( + const std::string& value, + float& result); + static bool parseOptionValue( const std::string& value, Tristate& result);