From 3747d4f01834fb890a7cad71b6ce9f9e05755028 Mon Sep 17 00:00:00 2001 From: "Alan M. Carroll" Date: Tue, 28 Aug 2018 15:26:07 -0500 Subject: [PATCH] TextView: Better support for std::string assignment. --- lib/ts/TextView.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/ts/TextView.h b/lib/ts/TextView.h index ce9f4e503ac..5c4fb28fa28 100644 --- a/lib/ts/TextView.h +++ b/lib/ts/TextView.h @@ -155,6 +155,7 @@ class TextView : public std::string_view /// Assignment. self_type &operator =(super_type const &that); template self_type &operator=(const char (&s)[N]); + self_type &operator =(const std::string &s); /// Explicitly set the view. self_type &assign(char const *ptr, size_t n); @@ -162,6 +163,9 @@ class TextView : public std::string_view /// Explicitly set the view to the range [ @a b , @a e ) self_type &assign(char const *b, char const *e); + /// Explicitly set the view from a @c std::string + self_type &assign(std::string const &s); + /// @return The first byte in the view. char operator*() const; @@ -576,6 +580,20 @@ TextView::operator=(super_type const &that) return *this; } +inline TextView & +TextView::operator=(const std::string &s) +{ + this->super_type::operator=(s); + return *this; +} + +inline TextView & +TextView::assign(const std::string &s) +{ + *this = super_type(s); + return *this; +} + inline TextView & TextView::assign(char const *ptr, size_t n) {