| 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> |
nothing calls this directly
no test coverage detected