You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dr...@apache.org on 2017/07/31 21:50:07 UTC
[trafficserver] branch master updated: Added constructor for
ats_scoped_str of std::string and string_view
This is an automated email from the ASF dual-hosted git repository.
dragon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 2519add Added constructor for ats_scoped_str of std::string and string_view
2519add is described below
commit 2519add20809f23a82c49e70863fa4ea034da827
Author: Xavier Chi <ch...@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 5a8e2d3..8968fa8 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
@@ -453,6 +455,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)
@@ -460,6 +478,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" <co...@trafficserver.apache.org>'].