From 475f05b6d27c23653dcfa030daa3125078f47541 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 7 Dec 2023 18:42:52 +0100 Subject: [PATCH] string: add strrchr and stricmp variants --- include/stdex/string.hpp | 52 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/include/stdex/string.hpp b/include/stdex/string.hpp index 5dbc5b14e..762894a1c 100644 --- a/include/stdex/string.hpp +++ b/include/stdex/string.hpp @@ -300,6 +300,20 @@ namespace stdex return npos; } + /// + /// Find a code unit in a string. + /// + /// \param[in] str String + /// \param[in] chr Code unit to search for + /// + /// \return Offset to the first occurence of chr code unit or stdex::npos if not found. + /// + template , class _Ax = std::allocator> + inline size_t strrchr(_In_ const std::basic_string& str, _In_ T chr) + { + return strrnchr(str.data(), str.size(), chr); + } + /// /// Find a code unit in a string. /// @@ -578,8 +592,8 @@ namespace stdex /// /// Binary compare two strings ASCII-case-insensitive /// - /// \param[in] str1 String 1 - /// \param[in] str2 String 2 + /// \param[in] str1 String 1 + /// \param[in] str2 String 2 /// /// \return Negative if str1str2; zero if str1==str2 /// @@ -598,6 +612,22 @@ namespace stdex return 0; } + /// + /// Binary compare two strings ASCII-case-insensitive + /// + /// \param[in] str1 String 1 + /// \param[in] str2 String 2 + /// + /// \return Negative if str1str2; zero if str1==str2 + /// + template , class _Ax1 = std::allocator, class T2, class _Traits2 = std::char_traits, class _Ax2 = std::allocator> + inline int stricmp( + _In_ const std::basic_string& str1, + _In_ const std::basic_string& str2) + { + return strnicmp(str1.data(), str1.size(), str2.data(), str2.size()); + } + /// /// Binary compare two strings case-insensitive /// @@ -624,6 +654,24 @@ namespace stdex return 0; } + /// + /// Binary compare two strings ASCII-case-insensitive + /// + /// \param[in] str1 String 1 + /// \param[in] str2 String 2 + /// \param[in] locale C++ locale to use + /// + /// \return Negative if str1str2; zero if str1==str2 + /// + template , class _Ax1 = std::allocator, class T2, class _Traits2 = std::char_traits, class _Ax2 = std::allocator> + inline int stricmp( + _In_ const std::basic_string& str1, + _In_ const std::basic_string& str2, + _In_ const std::locale& locale) + { + return strnicmp(str1.data(), str1.size(), str2.data(), str2.size(), locale); + } + /// /// Binary compare two strings ASCII-case-insensitive ///