diff --git a/ctl/string.cc b/ctl/string.cc index c30bf699d4c..0e73612827e 100644 --- a/ctl/string.cc +++ b/ctl/string.cc @@ -383,4 +383,10 @@ string::erase(const size_t pos, size_t count) noexcept return *this; } +void +string::append(const ctl::string_view& s, size_t pos, size_t count) noexcept +{ + append(s.substr(pos, count)); +} + } // namespace ctl diff --git a/ctl/string.h b/ctl/string.h index 6c92d8f9f9d..b88c903cbf6 100644 --- a/ctl/string.h +++ b/ctl/string.h @@ -125,6 +125,7 @@ class string void append(char, size_t) noexcept; void append(unsigned long) noexcept; void append(const void*, size_t) noexcept; + void append(const ctl::string_view&, size_t, size_t = npos) noexcept; string& insert(size_t, ctl::string_view) noexcept; string& erase(size_t = 0, size_t = npos) noexcept; string substr(size_t = 0, size_t = npos) const noexcept; @@ -302,7 +303,7 @@ class string append(ch); } - void append(const ctl::string_view s) noexcept + void append(const ctl::string_view& s) noexcept { append(s.p, s.n); } diff --git a/test/ctl/string_test.cc b/test/ctl/string_test.cc index 90b19e9c851..828e7eacc3a 100644 --- a/test/ctl/string_test.cc +++ b/test/ctl/string_test.cc @@ -404,5 +404,13 @@ main() } } + { + String s = "love"; + String b; + b.append(s, 1, 2); + if (b != "ov") + return 107; + } + CheckForMemoryLeaks(); }