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

Method ParseSingleValue

src/settings.cpp:188–198  ·  view source on GitHub ↗

* Find the index value of a ONEofMANY type in a string * @param str the current value of the setting for which a value needs found * @param many full domain of values the ONEofMANY setting can have * @return the integer index of the full-list, or std::nullopt if not found */

Source from the content-addressed store, hash-verified

186 * @return the integer index of the full-list, or std::nullopt if not found
187 */
188std::optional<uint32_t> OneOfManySettingDesc::ParseSingleValue(std::string_view str, std::span<const std::string_view> many)
189{
190 StringConsumer consumer{str};
191 auto digit = consumer.TryReadIntegerBase<uint32_t>(10);
192 /* check if it's an integer */
193 if (digit.has_value()) return digit;
194
195 auto it = std::ranges::find(many, str);
196 if (it == many.end()) return std::nullopt;
197 return static_cast<uint32_t>(it - many.begin());
198}
199
200/**
201 * Find whether a string was a boolean true or a boolean false.

Callers

nothing calls this directly

Calls 3

findFunction · 0.50
endMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected