Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 3 | #include <algorithm> |
| 4 | #include <ranges> |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 5 | #include <string> |
| 6 | #include <string_view> |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace bmcweb |
| 10 | { |
| 11 | // This is a naive replacement for boost::split until |
| 12 | // https://github.com/llvm/llvm-project/issues/40486 |
| 13 | // is resolved |
| 14 | inline void split(std::vector<std::string>& strings, std::string_view str, |
| 15 | char delim) |
| 16 | { |
| 17 | size_t start = 0; |
| 18 | size_t end = 0; |
Ed Tanous | b64c626 | 2023-02-21 10:27:14 -0800 | [diff] [blame] | 19 | while (end <= str.size()) |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 20 | { |
| 21 | end = str.find(delim, start); |
| 22 | strings.emplace_back(str.substr(start, end - start)); |
Ed Tanous | b64c626 | 2023-02-21 10:27:14 -0800 | [diff] [blame] | 23 | start = end + 1; |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 24 | } |
| 25 | } |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 26 | |
| 27 | inline char asciiToLower(char c) |
| 28 | { |
| 29 | // Converts a character to lower case without relying on std::locale |
| 30 | if ('A' <= c && c <= 'Z') |
| 31 | { |
| 32 | c -= ('A' - 'a'); |
| 33 | } |
| 34 | return c; |
| 35 | } |
| 36 | |
| 37 | inline bool asciiIEquals(std::string_view left, std::string_view right) |
| 38 | { |
| 39 | return std::ranges::equal(left, right, [](char lChar, char rChar) { |
| 40 | return asciiToLower(lChar) == asciiToLower(rChar); |
| 41 | }); |
| 42 | } |
| 43 | |
Ed Tanous | 50ebd4a | 2023-01-19 19:03:17 -0800 | [diff] [blame] | 44 | } // namespace bmcweb |