diff options
author | zxu <zxu@google.com> | 2018-01-27 17:53:27 -0500 |
---|---|---|
committer | Gil <mcg@google.com> | 2018-01-27 14:53:27 -0800 |
commit | af6976a907b0d2a9fadbb14d7258bab44f075364 (patch) | |
tree | 62918ca2d8da0696967e3003e495ba11cd56bf33 /Firestore/Source/Local/StringView.h | |
parent | 7226b4adf38e4732dfb9a840d25f86d3e5533bdb (diff) |
normalize and port the rest of Firebase/Port code (#713)
* normalize bits
* normalize ordered_code
Diffstat (limited to 'Firestore/Source/Local/StringView.h')
-rw-r--r-- | Firestore/Source/Local/StringView.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Firestore/Source/Local/StringView.h b/Firestore/Source/Local/StringView.h index b81b7b5..8156193 100644 --- a/Firestore/Source/Local/StringView.h +++ b/Firestore/Source/Local/StringView.h @@ -25,6 +25,7 @@ #include <leveldb/slice.h> #include <string> +#include "absl/strings/string_view.h" namespace Firestore { @@ -64,6 +65,10 @@ class StringView { StringView(leveldb::Slice slice) : data_(slice.data()), size_(slice.size()) { } + // Creates a StringView from the absl::string_view. + StringView(absl::string_view s) : data_(s.data()), size_(s.size()) { + } + // Creates a StringView from the given std::string. The string must be an // lvalue for the lifetime requirements to be satisfied. StringView(const std::string &str) : data_(str.data()), size_(str.size()) { @@ -76,6 +81,13 @@ class StringView { return leveldb::Slice(data_, size_); } + // Converts this StringView to a absl::string_view, which is an equivalent (and more + // functional) type. The returned string_view has the same lifetime as this + // StringView. + operator absl::string_view() { + return absl::string_view(data_, size_); + } + private: const char *data_; const size_t size_; |