diff options
| author | ilotterytea <iltsu@alright.party> | 2025-02-02 23:00:25 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2025-02-02 23:02:07 +0500 |
| commit | 58fdbd8edfbb85a06c6c4bc0edafa46faf0709ef (patch) | |
| tree | 6f446cf52e665acceb06518f7b843491b1e2a04d | |
| parent | f27bf2dfa4975c7366013bb2f729a9823105361c (diff) | |
feat: trim utils
| -rw-r--r-- | src/utils/string.cpp | 21 | ||||
| -rw-r--r-- | src/utils/string.hpp | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/utils/string.cpp b/src/utils/string.cpp index bb590ca..c0b7517 100644 --- a/src/utils/string.cpp +++ b/src/utils/string.cpp @@ -1,5 +1,8 @@ #include "string.hpp" +#include <algorithm> +#include <cctype> +#include <locale> #include <sstream> namespace silly::editor::utils { @@ -15,4 +18,22 @@ namespace silly::editor::utils { return parts; } + + void ltrim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); + } + + void rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), + [](unsigned char ch) { return !std::isspace(ch); }) + .base(), + s.end()); + } + + void trim(std::string &s) { + rtrim(s); + ltrim(s); + } }
\ No newline at end of file diff --git a/src/utils/string.hpp b/src/utils/string.hpp index cfee5b7..9ec766c 100644 --- a/src/utils/string.hpp +++ b/src/utils/string.hpp @@ -4,4 +4,7 @@ namespace silly::editor::utils { std::vector<std::string> split_text(const std::string &text, char delimiter); + void ltrim(std::string &s); + void rtrim(std::string &s); + void trim(std::string &s); }
\ No newline at end of file |
