Commit a2deb999 authored by captainwong's avatar captainwong

update

parent 4350ca0d
......@@ -99,4 +99,42 @@ inline std::wstring remove_all_copy(std::wstring str, wchar_t c) {
}
/**************************** case-conv ***************************/
void to_upper(std::string& str) {
std::for_each(str.begin(), str.end(), [](char& c) { c = ::toupper(c); });
}
void to_upper(std::wstring& str) {
std::for_each(str.begin(), str.end(), [](wchar_t& c) { c = ::toupper(c); });
}
std::string to_upper_copy(std::string str) {
std::for_each(str.begin(), str.end(), [](char& c) { c = ::toupper(c); });
return str;
}
std::wstring to_upper_copy(std::wstring str) {
std::for_each(str.begin(), str.end(), [](wchar_t& c) { c = ::toupper(c); });
return str;
}
void to_lower(std::string& str) {
std::for_each(str.begin(), str.end(), [](char& c) { c = ::tolower(c); });
}
void to_lower(std::wstring& str) {
std::for_each(str.begin(), str.end(), [](wchar_t& c) { c = ::tolower(c); });
}
std::string to_lower_copy(std::string str) {
std::for_each(str.begin(), str.end(), [](char& c) { c = ::tolower(c); });
return str;
}
std::wstring to_lower_copy(std::wstring str) {
std::for_each(str.begin(), str.end(), [](wchar_t& c) { c = ::tolower(c); });
return str;
}
} // namespace jlib
......@@ -58,4 +58,20 @@ int main()
remove_all(wstr, L'b'); assert(wstr == L"cc");
remove_all(wstr, L'c'); assert(wstr == L"");
}
// case-conv
{
string str = "abc";
assert(to_upper_copy(str) == "ABC");
to_upper(str); assert(str == "ABC");
assert(to_lower_copy(str) == "abc");
to_lower(str); assert(str == "abc");
wstring wstr = L"abc";
assert(to_upper_copy(wstr) == L"ABC");
to_upper(wstr); assert(wstr == L"ABC");
assert(to_lower_copy(wstr) == L"abc");
to_lower(wstr); assert(wstr == L"abc");
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment