aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/String.cpp9
-rw-r--r--src/common/StringUtil.cpp4
2 files changed, 13 insertions, 0 deletions
diff --git a/src/common/String.cpp b/src/common/String.cpp
index 743a33fd..8d674369 100644
--- a/src/common/String.cpp
+++ b/src/common/String.cpp
@@ -211,6 +211,15 @@ String::iterator String::erase(const_iterator start, const_iterator end) {
return s;
}
+String& String::TrimEnd() {
+ if (size_ == 0) return *this;
+ while (size_ > 0 && IsWhitespace(buffer_[size_ - 1])) {
+ size_--;
+ }
+
+ return *this;
+}
+
std::string String::ToUtf8() const { return cru::ToUtf8(buffer_, size_); }
void String::AppendCodePoint(CodePoint code_point) {
diff --git a/src/common/StringUtil.cpp b/src/common/StringUtil.cpp
index c828fa21..d3948c6a 100644
--- a/src/common/StringUtil.cpp
+++ b/src/common/StringUtil.cpp
@@ -252,4 +252,8 @@ char16_t ToUpper(char16_t c) {
}
return c;
}
+
+char16_t IsWhitespace(char16_t c) {
+ return c == u' ' || c == u'\t' || c == u'\n' || c == u'\r';
+}
} // namespace cru