From c338a04196f6b7083baf637225debb60f80c2331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sat, 10 Nov 2018 10:52:20 -0500 Subject: [PATCH] string_view: convert from std::string --- src/opustags.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/opustags.h b/src/opustags.h index f00d82b..37d1382 100644 --- a/src/opustags.h +++ b/src/opustags.h @@ -9,6 +9,7 @@ #include #include #include +#include namespace ot { @@ -20,18 +21,19 @@ namespace ot { */ class string_view { public: - string_view() {} - string_view(const char *data) : _data(data), _size(strlen(data)) {} - string_view(const char *data, size_t size) : _data(data), _size(size) {} - const char *data() const { return _data; } + string_view() : _data(nullptr), _size(0) {} + string_view(const char* data) : _data(data), _size(strlen(data)) {} + string_view(const char* data, size_t size) : _data(data), _size(size) {} + string_view(const std::string& str) : _data(str.data()), _size(str.size()) {} + const char* data() const { return _data; } size_t size() const { return _size; } bool operator==(const string_view &other) const { return _size == other._size && memcmp(_data, other._data, _size) == 0; } - bool operator!=(const string_view &other) const { return !(*this == other); } + bool operator!=(const string_view& other) const { return !(*this == other); } private: - const char *_data = nullptr; - size_t _size = 0; + const char* _data; + size_t _size; }; /**