22inline void NormalizeTag(std::string& value, std::size_t maxLen, std::string_view fallback, std::string_view what)
29 Log::Warn(
"settings: {} is empty or longer than {} chars; using \"{}\"", what, maxLen, fallback);
30 value = std::string(fallback);
35void FilterValid(std::vector<T>& items, std::invocable<const T&, std::size_t>
auto&& validate, std::string_view what)
38 kept.reserve(items.size());
39 for (std::size_t i = 0; i < items.size(); ++i)
41 if (
auto reason = validate(items[i], i))
43 Log::Warn(
"settings: skipping {}[{}]: {}", what, i, *reason);
47 kept.push_back(std::move(items[i]));
50 items = std::move(kept);
56bool FallbackIfEmpty(std::vector<T>& items,
const std::vector<T>& defaults, std::string_view what)
58 if (!items.empty() || defaults.empty())
63 Log::Warn(
"settings: {} has no valid entries; using built-in defaults", what);
72bool FallbackIfEmpty(std::vector<T>& items, std::invocable
auto&& makeDefaults, std::string_view what)
79 auto defaults = makeDefaults();
85 Log::Warn(
"settings: {} has no valid entries; using built-in defaults", what);
86 items = std::move(defaults);
92inline std::vector<int>
ParseDurations(
const std::vector<std::string>& entries,
93 const std::vector<std::string>& defaults, std::string_view what)
95 std::vector<std::string> kept = entries;
98 [](
const std::string& entry, std::size_t) -> std::optional<std::string> {
101 return std::format(
"bad duration '{}'", entry);
108 std::vector<int> result;
109 result.reserve(kept.size());
110 for (
const auto& entry : kept)
static std::string Trim(std::string_view str)
void Warn(std::format_string< Args... > fmt, Args &&... args)
void NormalizeTag(std::string &value, std::size_t maxLen, std::string_view fallback, std::string_view what)
Declarative helpers for post-load config validation: skip bad entries with a warning instead of faili...
void FilterValid(std::vector< T > &items, std::invocable< const T &, std::size_t > auto &&validate, std::string_view what)
bool FallbackIfEmpty(std::vector< T > &items, const std::vector< T > &defaults, std::string_view what)
std::vector< int > ParseDurations(const std::vector< std::string > &entries, const std::vector< std::string > &defaults, std::string_view what)
int ParseDuration(std::string_view text)