blob: 8ac54b9182a6262b43662030dfd8cbe2799fd38c [file] [log] [blame]
Ed Tanous50ebd4a2023-01-19 19:03:17 -08001#pragma once
2
Ed Tanous18f8f602023-07-18 10:07:23 -07003#include <algorithm>
4#include <ranges>
Ed Tanous50ebd4a2023-01-19 19:03:17 -08005#include <string>
6#include <string_view>
7#include <vector>
8
9namespace bmcweb
10{
11// This is a naive replacement for boost::split until
12// https://github.com/llvm/llvm-project/issues/40486
13// is resolved
14inline 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 Tanousb64c6262023-02-21 10:27:14 -080019 while (end <= str.size())
Ed Tanous50ebd4a2023-01-19 19:03:17 -080020 {
21 end = str.find(delim, start);
22 strings.emplace_back(str.substr(start, end - start));
Ed Tanousb64c6262023-02-21 10:27:14 -080023 start = end + 1;
Ed Tanous50ebd4a2023-01-19 19:03:17 -080024 }
25}
Ed Tanous18f8f602023-07-18 10:07:23 -070026
27inline 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
37inline 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 Tanous50ebd4a2023-01-19 19:03:17 -080044} // namespace bmcweb