| Index: mojo/public/cpp/bindings/string.h
|
| diff --git a/mojo/public/cpp/bindings/string.h b/mojo/public/cpp/bindings/string.h
|
| index e02f089a7cd98144d1396b7421b593b898818de9..5f22b4cec60e50a3dea525fbd2770a51a93cbd6b 100644
|
| --- a/mojo/public/cpp/bindings/string.h
|
| +++ b/mojo/public/cpp/bindings/string.h
|
| @@ -38,6 +38,9 @@ class String {
|
| String(const char chars[N])
|
| : value_(chars, N - 1), is_null_(false) {}
|
|
|
| + String(std::string&& other) : value_(std::move(other)), is_null_(false) {}
|
| + String(String&& other) : is_null_(true) { Swap(&other); }
|
| +
|
| template <typename U>
|
| static String From(const U& other) {
|
| return TypeConverter<String, U>::Convert(other);
|
| @@ -68,6 +71,18 @@ class String {
|
| return *this;
|
| }
|
|
|
| + String& operator=(std::string&& other) {
|
| + value_ = std::move(other);
|
| + is_null_ = false;
|
| + return *this;
|
| + }
|
| + String& operator=(String&& other) {
|
| + is_null_ = true;
|
| + value_.clear();
|
| + Swap(&other);
|
| + return *this;
|
| + }
|
| +
|
| bool is_null() const { return is_null_; }
|
|
|
| size_t size() const { return value_.size(); }
|
| @@ -80,6 +95,16 @@ class String {
|
| const std::string& get() const { return value_; }
|
| operator const std::string&() const { return value_; }
|
|
|
| + // Returns a const reference to the |std::string| managed by this class. If
|
| + // the string is null, this will be an empty std::string.
|
| + const std::string& storage() const { return value_; }
|
| +
|
| + // Passes the underlying storage and resets this string to null.
|
| + std::string PassStorage() {
|
| + is_null_ = true;
|
| + return std::move(value_);
|
| + }
|
| +
|
| void Swap(String* other) {
|
| std::swap(is_null_, other->is_null_);
|
| value_.swap(other->value_);
|
|
|