* Convert a string representation (external) of an integer-like setting to an integer. * @param str Input string that will be parsed based on the type of desc. * @return The value from the parse string, or the default value of the setting. */
| 365 | * @return The value from the parse string, or the default value of the setting. |
| 366 | */ |
| 367 | int32_t IntSettingDesc::ParseValue(std::string_view str) const |
| 368 | { |
| 369 | StringConsumer consumer{str}; |
| 370 | /* The actual settings value might be int32 or uint32. Read as int64 and just cast away the high bits. */ |
| 371 | auto value = consumer.TryReadIntegerBase<int64_t>(10); |
| 372 | if (!value.has_value()) { |
| 373 | _settings_error_list.emplace_back( |
| 374 | GetEncodedString(STR_CONFIG_ERROR), |
| 375 | GetEncodedString(STR_CONFIG_ERROR_INVALID_VALUE, str, this->GetName())); |
| 376 | return this->GetDefaultValue(); |
| 377 | } |
| 378 | if (consumer.AnyBytesLeft()) { |
| 379 | _settings_error_list.emplace_back( |
| 380 | GetEncodedString(STR_CONFIG_ERROR), |
| 381 | GetEncodedString(STR_CONFIG_ERROR_TRAILING_CHARACTERS, this->GetName())); |
| 382 | } |
| 383 | return static_cast<int32_t>(*value); |
| 384 | } |
| 385 | |
| 386 | int32_t OneOfManySettingDesc::ParseValue(std::string_view str) const |
| 387 | { |
no test coverage detected