forked from ritchielawrence/cmdow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst_utils.cpp
More file actions
34 lines (30 loc) · 990 Bytes
/
st_utils.cpp
File metadata and controls
34 lines (30 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//!
// st_utils.cpp - Implementation of string utility functions
//
// Copyright (c) 2025 David Cleland
//
#include "st_utils.hpp"
#include <algorithm>
#include <sstream>
#include <stdexcept>
bool stInsensitiveCmp(const std::string_view& str1, const std::string_view& str2)
{
return str1.size() == str2.size() &&
std::equal(str1.begin(), str1.end(), str2.begin(),
[](char a, char b) { return std::tolower(a) == std::tolower(b); });
}
std::string stToLower(std::string_view str)
{
std::string lowerStr = std::string(str);
std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), [](unsigned char c) { return std::tolower(c); });
return lowerStr;
}
// Helper function to create a constexpr string
template <std::size_t N>
constexpr std::array<char, N> make_constexpr_string(const char(&str)[N]) {
std::array<char, N> result{};
for (std::size_t i = 0; i < N; ++i) {
result[i] = str[i];
}
return result;
}