1 #pragma once
2
3 #include <algorithm>
4 #include <ranges>
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
split(std::vector<std::string> & strings,std::string_view str,char delim)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;
19 while (end <= str.size())
20 {
21 end = str.find(delim, start);
22 strings.emplace_back(str.substr(start, end - start));
23 start = end + 1;
24 }
25 }
26
asciiToLower(char c)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
asciiIEquals(std::string_view left,std::string_view right)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
44 } // namespace bmcweb
45