50 lines
1.2 KiB
C++
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
|