This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch 7.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 5d9041b26dde963114cf0c57473bfc03f5c099b0
Author: Xavier Chi <chitianha...@gmail.com>
AuthorDate: Mon Jul 31 16:01:54 2017 -0500

    Added constructor for ats_scoped_str of std::string and string_view
---
 lib/ts/ink_memory.h  | 38 ++++++++++++++++++++++++++++++++++++++
 lib/ts/string_view.h |  4 ----
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/lib/ts/ink_memory.h b/lib/ts/ink_memory.h
index 2eb08d8..4276b2f 100644
--- a/lib/ts/ink_memory.h
+++ b/lib/ts/ink_memory.h
@@ -27,7 +27,9 @@
 #include <string.h>
 #include <strings.h>
 #include <inttypes.h>
+#include <string>
 
+#include "ts/string_view.h"
 #include "ts/ink_config.h"
 
 #if HAVE_UNISTD_H
@@ -442,6 +444,22 @@ public:
   explicit ats_scoped_str(size_t n) : super(static_cast<char 
*>(ats_malloc(n))) {}
   /// Put string @a s in this container for cleanup.
   explicit ats_scoped_str(char *s) : super(s) {}
+  // constructor with std::string
+  explicit ats_scoped_str(const std::string &s)
+  {
+    if (s.empty())
+      _r = nullptr;
+    else
+      _r = strdup(s.c_str());
+  }
+  // constructor with string_view
+  explicit ats_scoped_str(const ts::string_view &s)
+  {
+    if (s.empty())
+      _r = nullptr;
+    else
+      _r = strdup(s.data());
+  }
   /// Assign a string @a s to this container.
   self &
   operator=(char *s)
@@ -449,6 +467,26 @@ public:
     super::operator=(s);
     return *this;
   }
+  // std::string case
+  self &
+  operator=(const std::string &s)
+  {
+    if (s.empty())
+      _r = nullptr;
+    else
+      _r = strdup(s.c_str());
+    return *this;
+  }
+  // string_view case
+  self &
+  operator=(const ts::string_view &s)
+  {
+    if (s.empty())
+      _r = nullptr;
+    else
+      _r = strdup(s.data());
+    return *this;
+  }
 };
 
 /** Specialization of @c ats_scoped_resource for pointers allocated with @c 
ats_malloc.
diff --git a/lib/ts/string_view.h b/lib/ts/string_view.h
index ff902bf..87b5ca4 100644
--- a/lib/ts/string_view.h
+++ b/lib/ts/string_view.h
@@ -33,7 +33,6 @@
 #include <utility>
 #include <string>
 #include <ostream>
-#include <ts/ink_memory.h>
 
 #if __cplusplus < 201402
 #define CONSTEXPR14 inline
@@ -241,9 +240,6 @@ public:
   // std::string constructor
   constexpr basic_string_view(std::string const &rhs) noexcept : 
m_data(rhs.data()), m_size(rhs.size()) {}
 
-  // ats_scoped_str constructor
-  constexpr basic_string_view(ats_scoped_str const &rhs) noexcept : 
m_data(rhs.get()), m_size(traits_type::length(rhs.get())) {}
-
   // For iterator on string_view we don't need to deal with const and 
non-const as different types
   // they are all const iterators as the string values are immutable
   // keep in mind that the string view is mutable in what it points to

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>.

Reply via email to