X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/ec6a4a831e57834bf4d7abb91fc8b298c2fbfcc2..cc9745a0d81a3e1aa5ef6f99f7ad638d26bdb950:/apt-pkg/contrib/string_view.h?ds=sidebyside diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h index ea38224e8..f158ef8d6 100644 --- a/apt-pkg/contrib/string_view.h +++ b/apt-pkg/contrib/string_view.h @@ -13,6 +13,7 @@ #define APT_STRINGVIEW_H #include #include +#include namespace APT { @@ -23,14 +24,10 @@ namespace APT { * used by APT. It is not meant to be used in programs, only inside the * library for performance critical paths. */ -class StringView { +class APT_HIDDEN StringView { const char *data_; size_t size_; - // without this little stunt the "char const *" overload is always preferred - // over char[], but if we got a char[] we can deduct the length at compile time - #define APT_T_IS_CHARPOINTER template{} && !std::is_array{}>::type* = nullptr> - public: static constexpr size_t npos = static_cast(-1); static_assert(APT::StringView::npos == std::string::npos, "npos values are different"); @@ -39,11 +36,10 @@ public: constexpr StringView() : data_(""), size_(0) {} constexpr StringView(const char *data, size_t size) : data_(data), size_(size) {} - template constexpr StringView(char const (&data)[N]) : StringView(data, N-1) {} - APT_T_IS_CHARPOINTER StringView(T data) : data_(data), size_(strlen(data)) {} - + StringView(const char *data) : data_(data), size_(strlen(data)) {} StringView(std::string const & str): data_(str.data()), size_(str.size()) {} + /* Viewers */ constexpr StringView substr(size_t pos, size_t n = npos) const { return StringView(data_ + pos, n > (size_ - pos) ? (size_ - pos) : n); @@ -119,8 +115,7 @@ public: } -template inline bool operator ==(char const (&other)[N], APT::StringView that) { return that.operator==(other); } -APT_T_IS_CHARPOINTER inline bool operator ==(T other, APT::StringView that) { return that.operator==(other); } +inline bool operator ==(const char *other, APT::StringView that); +inline bool operator ==(const char *other, APT::StringView that) { return that.operator==(other); } -#undef APT_T_IS_CHARPOINTER #endif