diff options
author | crupest <crupest@outlook.com> | 2022-01-08 19:24:44 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-01-08 19:24:44 +0800 |
commit | 0c7153db084060034092c1dc24222cae384722ec (patch) | |
tree | 9de1bc4636732e3cc1e1fb7309fdf2ff60683f69 /src/common/String.cpp | |
parent | c38f1f7c273e85c0a6d197cb27424c9ca69e234d (diff) | |
download | cru-0c7153db084060034092c1dc24222cae384722ec.tar.gz cru-0c7153db084060034092c1dc24222cae384722ec.tar.bz2 cru-0c7153db084060034092c1dc24222cae384722ec.zip |
...
Diffstat (limited to 'src/common/String.cpp')
-rw-r--r-- | src/common/String.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/common/String.cpp b/src/common/String.cpp index ade2a72d..1c2ff022 100644 --- a/src/common/String.cpp +++ b/src/common/String.cpp @@ -206,7 +206,7 @@ String::iterator String::erase(const_iterator start, const_iterator end) { auto s = const_cast<iterator>(start); auto e = const_cast<iterator>(end); - std::memmove(e, s, (cend() - end) * sizeof(value_type)); + std::memmove(s, e, (cend() - end) * sizeof(value_type)); this->size_ = new_size; this->buffer_[new_size] = 0; @@ -298,6 +298,16 @@ std::vector<String> String::SplitToLines(bool remove_space_line) const { return result; } +bool String::StartWith(StringView str) const { + if (str.size() > size_) return false; + return std::memcmp(str.data(), buffer_, str.size()) == 0; +} + +bool String::EndWith(StringView str) const { + if (str.size() > size_) return false; + return std::memcmp(str.data(), buffer_ + size_ - str.size(), str.size()) == 0; +} + std::string String::ToUtf8() const { return cru::ToUtf8(buffer_, size_); } void String::AppendCodePoint(CodePoint code_point) { |