| 518 | /// Check that mapping contains valid units. |
| 519 | /// Update mapping for CASE_INSENSITIVE mode. |
| 520 | template <typename Number> static void validate_mapping(std::map<std::string, Number> &mapping, Options opts) { |
| 521 | for(auto &kv : mapping) { |
| 522 | if(kv.first.empty()) { |
| 523 | throw ValidationError("Unit must not be empty."); |
| 524 | } |
| 525 | if(!detail::isalpha(kv.first)) { |
| 526 | throw ValidationError("Unit must contain only letters."); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | // make all units lowercase if CASE_INSENSITIVE |
| 531 | if(opts & CASE_INSENSITIVE) { |
| 532 | std::map<std::string, Number> lower_mapping; |
| 533 | for(auto &kv : mapping) { |
| 534 | auto s = detail::to_lower(kv.first); |
| 535 | if(lower_mapping.count(s)) { |
| 536 | throw ValidationError(std::string("Several matching lowercase unit representations are found: ") + |
| 537 | s); |
| 538 | } |
| 539 | lower_mapping[detail::to_lower(kv.first)] = kv.second; |
| 540 | } |
| 541 | mapping = std::move(lower_mapping); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | /// Generate description like this: NUMBER [UNIT] |
| 546 | template <typename Number> static std::string generate_description(const std::string &name, Options opts) { |
nothing calls this directly
no test coverage detected