MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ParseValue

Method ParseValue

src/settings.cpp:367–384  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

365 * @return The value from the parse string, or the default value of the setting.
366 */
367int32_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
386int32_t OneOfManySettingDesc::ParseValue(std::string_view str) const
387{

Callers 3

IsSameValueMethod · 0.95
IniLoadSettingsFunction · 0.45
IConsoleSetSettingFunction · 0.45

Calls 12

GetDefaultValueMethod · 0.95
LookupManyOfManyFunction · 0.85
GetVariableAddressFunction · 0.85
LoadIntListFunction · 0.85
GetVarMemTypeFunction · 0.85
AnyBytesLeftMethod · 0.80
MakeValueValidMethod · 0.80
GetEncodedStringFunction · 0.70
GetNameMethod · 0.45
WriteMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected