MCPcopy Create free account
hub / github.com/Tencent/TAD_Sim / validate_mapping

Method validate_mapping

simcore/framework/src/cli/cli.hpp:3028–3050  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3026 /// Update mapping for CASE_INSENSITIVE mode.
3027 template <typename Number>
3028 static void validate_mapping(std::map<std::string, Number> &mapping, Options opts) {
3029 for (auto &kv : mapping) {
3030 if (kv.first.empty()) {
3031 throw ValidationError("Unit must not be empty.");
3032 }
3033 if (!detail::isalpha(kv.first)) {
3034 throw ValidationError("Unit must contain only letters.");
3035 }
3036 }
3037
3038 // make all units lowercase if CASE_INSENSITIVE
3039 if (opts & CASE_INSENSITIVE) {
3040 std::map<std::string, Number> lower_mapping;
3041 for (auto &kv : mapping) {
3042 auto s = detail::to_lower(kv.first);
3043 if (lower_mapping.count(s)) {
3044 throw ValidationError(std::string("Several matching lowercase unit representations are found: ") + s);
3045 }
3046 lower_mapping[detail::to_lower(kv.first)] = kv.second;
3047 }
3048 mapping = std::move(lower_mapping);
3049 }
3050 }
3051
3052 /// Generate description like this: NUMBER [UNIT]
3053 template <typename Number>

Callers

nothing calls this directly

Calls 5

ValidationErrorClass · 0.85
isalphaFunction · 0.85
to_lowerFunction · 0.85
emptyMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected