blob: 31c44b482fc0b2c4b5447aedbecaa534617cdfc7 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanous50ebd4a2023-01-19 19:03:17 -08003#pragma once
4
Ed Tanous18f8f602023-07-18 10:07:23 -07005#include <algorithm>
Ed Tanousd7857202025-01-28 15:32:26 -08006#include <cstddef>
Ed Tanous18f8f602023-07-18 10:07:23 -07007#include <ranges>
Ed Tanous50ebd4a2023-01-19 19:03:17 -08008#include <string>
9#include <string_view>
10#include <vector>
11
12namespace bmcweb
13{
14// This is a naive replacement for boost::split until
15// https://github.com/llvm/llvm-project/issues/40486
16// is resolved
17inline void split(std::vector<std::string>& strings, std::string_view str,
18 char delim)
19{
20 size_t start = 0;
21 size_t end = 0;
Ed Tanousb64c6262023-02-21 10:27:14 -080022 while (end <= str.size())
Ed Tanous50ebd4a2023-01-19 19:03:17 -080023 {
24 end = str.find(delim, start);
25 strings.emplace_back(str.substr(start, end - start));
Ed Tanousb64c6262023-02-21 10:27:14 -080026 start = end + 1;
Ed Tanous50ebd4a2023-01-19 19:03:17 -080027 }
28}
Ed Tanous18f8f602023-07-18 10:07:23 -070029
30inline char asciiToLower(char c)
31{
32 // Converts a character to lower case without relying on std::locale
33 if ('A' <= c && c <= 'Z')
34 {
35 c -= ('A' - 'a');
36 }
37 return c;
38}
39
40inline bool asciiIEquals(std::string_view left, std::string_view right)
41{
42 return std::ranges::equal(left, right, [](char lChar, char rChar) {
43 return asciiToLower(lChar) == asciiToLower(rChar);
44 });
45}
46
Ed Tanous50ebd4a2023-01-19 19:03:17 -080047} // namespace bmcweb