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 | 72940008 | inline std::string ascii_to_lower_copy(std::string_view input) { | |
| 15 |
1/1✓ Branch 1 taken 72940008 times.
|
72940008 | std::string result{input}; |
| 16 | 72940008 | constexpr auto to_lower_diff = 'a' - 'A'; | |
| 17 |
2/2✓ Branch 5 taken 1984750276 times.
✓ Branch 6 taken 72940008 times.
|
2057690284 | for (auto& c : result) { |
| 18 |
4/4✓ Branch 0 taken 1688509741 times.
✓ Branch 1 taken 296240535 times.
✓ Branch 2 taken 120034854 times.
✓ Branch 3 taken 1568474887 times.
|
1984750276 | if (c >= 'A' && c <= 'Z') { |
| 19 | 120034854 | c += to_lower_diff; | |
| 20 | } | ||
| 21 | } | ||
| 22 | 72940008 | 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 | 284552998 | inline std::string_view ascii_trim_left(std::string_view s) { | |
| 37 |
1/1✓ Branch 4 taken 284552998 times.
|
284552998 | return s.substr(std::min(s.find_first_not_of(" \f\n\r\t\v"), s.size())); |
| 38 | } | ||
| 39 | |||
| 40 | 284554701 | inline std::string_view ascii_trim_right(std::string_view s) { | |
| 41 |
1/1✓ Branch 4 taken 284554701 times.
|
284554701 | return s.substr(0, std::min(s.find_last_not_of(" \f\n\r\t\v") + 1, s.size())); |
| 42 | } | ||
| 43 | |||
| 44 | 284552997 | inline std::string_view ascii_trim(std::string_view s) { | |
| 45 | 284552997 | return ascii_trim_left(ascii_trim_right(s)); | |
| 46 | } | ||
| 47 | |||
| 48 | 284552997 | inline void ascii_trim(std::string& str) { | |
| 49 |
2/2✓ Branch 2 taken 284552997 times.
✓ Branch 5 taken 284552997 times.
|
284552997 | str = std::string(ascii_trim(std::string_view(str))); |
| 50 | 284552997 | } | |
| 51 | |||
| 52 | } // namespace openstudio | ||
| 53 | |||
| 54 | #endif | ||
| 55 |