From 72bab6d6b22c706af92247ff20835cc98a361e54 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 7 Dec 2023 12:27:38 +0100 Subject: [PATCH] string: add strlwr variants --- include/stdex/string.hpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index af271c7e5..5dbc5b14e 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -1770,6 +1770,18 @@ namespace stdex str[i] = tolower(str[i]); } + /// + /// Convert string to lower-case character-by-character + /// + /// \param[in,out] str String + /// + template, class _Ax = std::allocator<_Elem>> + inline void strlwr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str) + { + for (auto& c : str) + c = tolower(c); + } + /// /// Convert string to lower-case character-by-character /// @@ -1786,6 +1798,20 @@ namespace stdex str[i] = ctype.tolower(str[i]); } + /// + /// Convert string to lower-case character-by-character + /// + /// \param[in,out] str String + /// \param[in] locale C++ locale to use + /// + template, class _Ax = std::allocator<_Elem>> + inline void strlwr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str, _In_ const std::locale& locale) + { + const auto& ctype = std::use_facet>(locale); + for (auto& c : str) + c = ctype.tolower(c); + } + /// /// Convert string to ASCII-upper-case character-by-character /// @@ -1852,8 +1878,8 @@ namespace stdex template, class _Ax = std::allocator<_Elem>> inline void strupr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str) { - for (size_t i = 0; i < str.size(); ++i) - str[i] = toupper(str[i]); + for (auto& c : str) + c = toupper(c); } /// @@ -1866,8 +1892,8 @@ namespace stdex inline void strupr(_Inout_ std::basic_string<_Elem, _Traits, _Ax>& str, _In_ const std::locale& locale) { const auto& ctype = std::use_facet>(locale); - for (size_t i = 0; i < str.size(); ++i) - str[i] = ctype.toupper(str[i]); + for (auto& c : str) + c = ctype.toupper(c); } ///