Port a few common utils from development branch

This is a prereq to cherry-picking the commit to upgrade fmt to v10.0.0
This commit is contained in:
John Colvin committed 2023-12-23 13:12:30 -05:00
1 parent d24becd052
commit d5e6b00534
15 files changed
+1523 -19

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
#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