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