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

Function LookupManyOfMany

src/settings.cpp:221–240  ·  view source on GitHub ↗

* Find the set-integer value MANYofMANY type in a string * @param many full domain of values the MANYofMANY setting can have * @param str the current string value of the setting, each individual * of separated by a whitespace, tab or | character * @return the 'fully' set integer, or std::nullopt if a set is not found */

Source from the content-addressed store, hash-verified

219 * @return the 'fully' set integer, or std::nullopt if a set is not found
220 */
221static std::optional<uint32_t> LookupManyOfMany(std::span<const std::string_view> many, std::string_view str)
222{
223 static const std::string_view separators{" \t|"};
224
225 uint32_t res = 0;
226 StringConsumer consumer{str};
227 while (consumer.AnyBytesLeft()) {
228 /* skip "whitespace" */
229 consumer.SkipUntilCharNotIn(separators);
230
231 std::string_view value = consumer.ReadUntilCharIn(separators);
232 if (value.empty()) break;
233
234 auto r = OneOfManySettingDesc::ParseSingleValue(value, many);
235 if (!r.has_value()) return r;
236
237 SetBit(res, *r); // value found, set it
238 }
239 return res;
240}
241
242/**
243 * Parse a string into a vector of uint32s.

Callers 1

ParseValueMethod · 0.85

Calls 5

SetBitFunction · 0.85
AnyBytesLeftMethod · 0.80
SkipUntilCharNotInMethod · 0.80
ReadUntilCharInMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected