Files
spark/src/lib/algorithm/StringCaseConverter.h
T
John Colvin d5e6b00534 Port a few common utils from development branch
This is a prereq to cherry-picking the commit to upgrade fmt to v10.0.0
2023-12-23 13:12:30 -05:00

50 lines
1.2 KiB
C++

#pragma once
#include <string>
namespace bts::algorithm {
class StringCaseConverter {
public:
static void to_upper(const std::string &str, std::string &dest) noexcept;
static std::string to_upper(const std::string &str) noexcept;
static void to_lower(const std::string &str, std::string &dest) noexcept;
static std::string to_lower(const std::string &str) noexcept;
};
//////////////////////////////////////////////////
// Definition
//////////////////////////////////////////////////
inline std::string StringCaseConverter::to_upper(const std::string &str) noexcept {
std::string rv{str};
for (auto &c : rv) {
c = std::toupper(c);
}
return rv;
}
inline void StringCaseConverter::to_upper(const std::string &str, std::string &dest) noexcept {
dest = str;
for (auto &c : dest) {
c = std::toupper(c);
}
}
inline std::string StringCaseConverter::to_lower(const std::string &str) noexcept {
std::string rv{str};
for (auto &c : rv) {
c = std::tolower(c);
}
return rv;
}
inline void StringCaseConverter::to_lower(const std::string &str, std::string &dest) noexcept {
dest = str;
for (auto &c : dest) {
c = std::tolower(c);
}
}
} // namespace bts::algorithm