aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Wankadia <junyer@google.com>2019-01-21 21:33:24 -0800
committerPaul Wankadia <junyer@google.com>2019-01-22 05:35:17 +0000
commit1763a753b2f8f1216dc16f4687d72c4ad8e42d92 (patch)
treef5b4aa8f240ce30cec352855c036349f094ad3db
parent29dd8fdd63edb04f913a6559ddba6dc8c773d797 (diff)
downloadregex-re2-1763a753b2f8f1216dc16f4687d72c4ad8e42d92.tar.gz
Support constructing StringPiece from std::string_view.
Change-Id: I12ea795d2ff0aae99683ceb9afeb2569941b4dbf Reviewed-on: https://code-review.googlesource.com/c/37631 Reviewed-by: Paul Wankadia <junyer@google.com>
-rw-r--r--re2/stringpiece.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/re2/stringpiece.h b/re2/stringpiece.h
index 1db7a2a..0181671 100644
--- a/re2/stringpiece.h
+++ b/re2/stringpiece.h
@@ -19,12 +19,20 @@
//
// Arghh! I wish C++ literals were "string".
+// Doing this simplifies the logic below.
+#ifndef __has_include
+#define __has_include(x) 0
+#endif
+
#include <stddef.h>
#include <string.h>
#include <algorithm>
#include <iosfwd>
#include <iterator>
#include <string>
+#if __has_include(<string_view>)
+#include <string_view>
+#endif
namespace re2 {
@@ -49,6 +57,10 @@ class StringPiece {
// expected.
StringPiece()
: data_(NULL), size_(0) {}
+#if __has_include(<string_view>)
+ StringPiece(const std::string_view& str)
+ : data_(str.data()), size_(str.size()) {}
+#endif
StringPiece(const std::string& str)
: data_(str.data()), size_(str.size()) {}
StringPiece(const char* str)