src/utilities/core/ASCIIStrings.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_CORE_ASCIISTRINGS_HPP | ||
| 7 | #define UTILITIES_CORE_ASCIISTRINGS_HPP | ||
| 8 | |||
| 9 | #include <string> | ||
| 10 | #include <string_view> | ||
| 11 | |||
| 12 | namespace openstudio { | ||
| 13 | |||
| 14 | 72894936 | inline std::string ascii_to_lower_copy(std::string_view input) { | |
| 15 |
1/1✓ Branch 1 taken 72894936 times.
|
72894936 | std::string result{input}; |
| 16 | 72894936 | constexpr auto to_lower_diff = 'a' - 'A'; | |
| 17 |
2/2✓ Branch 5 taken 1983550922 times.
✓ Branch 6 taken 72894936 times.
|
2056445858 | for (auto& c : result) { |
| 18 |
4/4✓ Branch 0 taken 1687463392 times.
✓ Branch 1 taken 296087530 times.
✓ Branch 2 taken 119955054 times.
✓ Branch 3 taken 1567508338 times.
|
1983550922 | if (c >= 'A' && c <= 'Z') { |
| 19 | 119955054 | c += to_lower_diff; | |
| 20 | } | ||
| 21 | } | ||
| 22 | 72894936 | return result; | |
| 23 | } | ||
| 24 | |||
| 25 | 8 | inline std::string ascii_to_upper_copy(std::string_view input) { | |
| 26 |
1/1✓ Branch 1 taken 8 times.
|
8 | std::string result{input}; |
| 27 | 8 | constexpr auto to_upper_diff = 'A' - 'a'; | |
| 28 |
2/2✓ Branch 5 taken 191 times.
✓ Branch 6 taken 8 times.
|
199 | for (auto& c : result) { |
| 29 |
3/4✓ Branch 0 taken 156 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 156 times.
✗ Branch 3 not taken.
|
191 | if (c >= 'a' && c <= 'z') { |
| 30 | 156 | c += to_upper_diff; | |
| 31 | } | ||
| 32 | } | ||
| 33 | 8 | return result; | |
| 34 | } | ||
| 35 | |||
| 36 | 284411638 | inline std::string_view ascii_trim_left(std::string_view s) { | |
| 37 |
1/1✓ Branch 4 taken 284411638 times.
|
284411638 | return s.substr(std::min(s.find_first_not_of(" \f\n\r\t\v"), s.size())); |
| 38 | } | ||
| 39 | |||
| 40 | 284413341 | inline std::string_view ascii_trim_right(std::string_view s) { | |
| 41 |
1/1✓ Branch 4 taken 284413341 times.
|
284413341 | return s.substr(0, std::min(s.find_last_not_of(" \f\n\r\t\v") + 1, s.size())); |
| 42 | } | ||
| 43 | |||
| 44 | 284411637 | inline std::string_view ascii_trim(std::string_view s) { | |
| 45 | 284411637 | return ascii_trim_left(ascii_trim_right(s)); | |
| 46 | } | ||
| 47 | |||
| 48 | 284411637 | inline void ascii_trim(std::string& str) { | |
| 49 |
2/2✓ Branch 2 taken 284411637 times.
✓ Branch 5 taken 284411637 times.
|
284411637 | str = std::string(ascii_trim(std::string_view(str))); |
| 50 | 284411637 | } | |
| 51 | |||
| 52 | } // namespace openstudio | ||
| 53 | |||
| 54 | #endif | ||
| 55 |