* @brief Validates that the provided AnyMap conforms to the same constraints that * those stored in Property objects have. * * The provided AnyMap is said to be valid if there exists no pairs of two keys * which differ in case only (e.g., "service.feature", "Service.feature"). If this * condition is not true, this function throws as defined below.
| 43 | * @throws std::runtime_error Thrown when `am` is invalid (described above) |
| 44 | */ |
| 45 | void |
| 46 | ValidateAnyMap(cppmicroservices::AnyMap const& am) |
| 47 | { |
| 48 | std::vector<std::string_view> keys(am.size()); |
| 49 | uint32_t currIndex = 0; |
| 50 | for (auto& kv_pair : am) |
| 51 | { |
| 52 | keys[currIndex++] = kv_pair.first; |
| 53 | } |
| 54 | |
| 55 | if (am.size() > 1) |
| 56 | { |
| 57 | // NOTE: A solution involving iterations rather than "raw for-loops" was previously |
| 58 | // tested but ended up being slower than the solution below. |
| 59 | for (uint32_t i = 0; i < keys.size() - 1; ++i) |
| 60 | { |
| 61 | for (uint32_t j = i + 1; j < keys.size(); ++j) |
| 62 | { |
| 63 | if (keys[i].size() == keys[j].size() |
| 64 | && ci_compare(keys[i].data(), keys[j].data(), keys[i].size()) == 0) |
| 65 | { |
| 66 | std::string msg("Properties contain case variants of the key: "); |
| 67 | msg += keys[i]; |
| 68 | throw std::runtime_error(msg.c_str()); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | std::string |
| 76 | ToLower(std::string const& s) |
no test coverage detected