Skip to content

Commit

Permalink
feat(iString): add ltrim,rtrim,trim.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lovelylavender4 committed Mar 16, 2024
1 parent 94afcca commit 217fa2d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions iVerse/include/string/iString.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ namespace String
std::transform(basic_string::begin(), basic_string::end(), basic_string::begin(), std::tolower);
}

iString ltrim(CRef<iString> 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<iString> 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<iString> s) { return ltrim(rtrim(s)); }

public:
// Overloading from u8string::push_back
void push_back(CRef<iString> string)
Expand Down

0 comments on commit 217fa2d

Please sign in to comment.