From 217fa2d7e0cc05e0b398d4744437929c27268de1 Mon Sep 17 00:00:00 2001 From: Lovelylavender4 Date: Sat, 16 Mar 2024 22:39:49 +0800 Subject: [PATCH] feat(iString): add ltrim,rtrim,trim. --- iVerse/include/string/iString.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/iVerse/include/string/iString.h b/iVerse/include/string/iString.h index 6e9fd4b..0fcf98a 100644 --- a/iVerse/include/string/iString.h +++ b/iVerse/include/string/iString.h @@ -273,6 +273,22 @@ namespace String std::transform(basic_string::begin(), basic_string::end(), basic_string::begin(), std::tolower); } + iString ltrim(CRef str) + { + iString s = str; + auto notSpace = [](unsigned char ch) { return !std::isspace(ch); }; + s.erase(s.begin(), std::find_if(s.begin(), s.end(), notSpace)); + return s; + } + iString rtrim(CRef str) + { + iString s = str; + auto notSpace = [](unsigned char ch) { return !std::isspace(ch); }; + s.erase(std::find_if(s.rbegin(), s.rend(), notSpace).base(), s.end()); + return s; + } + iString trim(CRef s) { return ltrim(rtrim(s)); } + public: // Overloading from u8string::push_back void push_back(CRef string)