diff options
| author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2024-11-12 18:22:44 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-14 19:45:12 +0100 |
| commit | 4f6d379124bc51a09608fa3f45d66713f927b959 (patch) | |
| tree | b20d5437d722deb919d92f06498402d23e53eef6 | |
| parent | 793c9b1f3059c35b66c19f62fa39b6607809fea0 (diff) | |
Drop APT::StringView
| -rw-r--r-- | apt-pkg/contrib/proxy.cc | 3 | ||||
| -rw-r--r-- | apt-pkg/contrib/string_view.h | 170 | ||||
| -rw-r--r-- | apt-pkg/deb/deblistparser.cc | 19 | ||||
| -rw-r--r-- | apt-pkg/deb/deblistparser.h | 9 | ||||
| -rw-r--r-- | apt-pkg/pkgcache.cc | 1 | ||||
| -rw-r--r-- | apt-pkg/pkgcachegen.cc | 2 | ||||
| -rw-r--r-- | test/libapt/stringview_test.cc | 99 |
7 files changed, 2 insertions, 301 deletions
diff --git a/apt-pkg/contrib/proxy.cc b/apt-pkg/contrib/proxy.cc index aad272190..4780f9b5a 100644 --- a/apt-pkg/contrib/proxy.cc +++ b/apt-pkg/contrib/proxy.cc @@ -12,7 +12,6 @@ #include <apt-pkg/configuration.h> #include <apt-pkg/error.h> #include <apt-pkg/fileutl.h> -#include <apt-pkg/string_view.h> #include <apt-pkg/strutl.h> #include <algorithm> @@ -89,7 +88,7 @@ bool AutoDetectProxy(URI &URL) // and apt will use the generic proxy settings if (goodread == false) return true; - APT::StringView const cleanedbuf = _strstrip(buf); + std::string_view const cleanedbuf = _strstrip(buf); // We warn about this as the implementor probably meant to use DIRECT instead if (cleanedbuf.empty()) { diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h deleted file mode 100644 index 538e79a92..000000000 --- a/apt-pkg/contrib/string_view.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Basic implementation of string_view - * - * (C) 2015 Julian Andres Klode <jak@debian.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ - -#if !defined(APT_STRINGVIEW_H) -#define APT_STRINGVIEW_H -#include <apt-pkg/macros.h> -#include <algorithm> -#include <cstring> -#include <iosfwd> -#include <string> -#include <string_view> - -#if APT_PKG_ABI > 600 -namespace APT { -using StringView = std::string_view; -} -#else -namespace APT { - -/** - * \brief Simple subset of std::string_view from C++17 - * - * This is an internal implementation of the subset of std::string_view - * used by APT. It is not meant to be used in programs, only inside the - * library for performance critical paths. - */ -class StringView { - const char *data_; - size_t size_; - -public: - static constexpr size_t npos = static_cast<size_t>(-1); - static_assert(APT::StringView::npos == std::string::npos, "npos values are different"); - - /* Constructors */ - constexpr StringView() : data_(""), size_(0) {} - constexpr StringView(const char *data, size_t size) : data_(data), size_(size) {} - - StringView(const char *data) : data_(data), size_(strlen(data)) {} - StringView(std::string const & str): data_(str.data()), size_(str.size()) {} - inline StringView(std::string_view const & str): data_(str.data()), size_(str.size()) {} - - /* Modifiers */ - void remove_prefix(size_t n) { data_ += n; size_ -= n; } - void remove_suffix(size_t n) { size_ -= n; } - void clear() { size_ = 0; } - - /* Viewers */ - constexpr StringView substr(size_t pos, size_t n = npos) const { - return StringView(data_ + pos, n > (size_ - pos) ? (size_ - pos) : n); - } - - size_t find(int c, size_t pos) const { - if (pos == 0) - return find(c); - size_t const found = substr(pos).find(c); - if (found == npos) - return npos; - return pos + found; - } - size_t find(int c) const { - const char *found = static_cast<const char*>(memchr(data_, c, size_)); - - if (found == NULL) - return npos; - - return found - data_; - } - - size_t rfind(int c, size_t pos) const { - if (pos == npos) - return rfind(c); - return APT::StringView(data_, pos).rfind(c); - } - size_t rfind(int c) const { - const char *found = static_cast<const char*>(memrchr(data_, c, size_)); - - if (found == NULL) - return npos; - - return found - data_; - } - - size_t find(APT::StringView const needle) const { - if (needle.empty()) - return npos; - if (needle.length() == 1) - return find(*needle.data()); - size_t found = 0; - while ((found = find(*needle.data(), found)) != npos) { - if (compare(found, needle.length(), needle) == 0) - return found; - ++found; - } - return found; - } - size_t find(APT::StringView const needle, size_t pos) const { - if (pos == 0) - return find(needle); - size_t const found = substr(pos).find(needle); - if (found == npos) - return npos; - return pos + found; - } - - /* Conversions */ - std::string to_string() const { - return std::string(data_, size_); - } - - /* Comparisons */ - int compare(size_t pos, size_t n, StringView other) const { - return substr(pos, n).compare(other); - } - - int compare(StringView other) const { - int res; - - res = memcmp(data_, other.data_, std::min(size_, other.size_)); - if (res != 0) - return res; - if (size_ == other.size_) - return res; - - return (size_ > other.size_) ? 1 : -1; - } - - /* Optimization: If size not equal, string cannot be equal */ - bool operator ==(StringView other) const { return size_ == other.size_ && compare(other) == 0; } - bool operator !=(StringView other) const { return !(*this == other); } - - /* Accessors */ - constexpr bool empty() const { return size_ == 0; } - constexpr const char* data() const { return data_; } - constexpr const char* begin() const { return data_; } - constexpr const char* end() const { return data_ + size_; } - constexpr char operator [](size_t i) const { return data_[i]; } - constexpr size_t size() const { return size_; } - constexpr size_t length() const { return size_; } - - inline constexpr operator std::string_view() const { return {data_, size_}; } -}; - -inline std::ostream& operator<<(std::ostream& os, const StringView& sv) -{ - return os << static_cast<std::string_view>(sv); -} - -static constexpr inline APT::StringView operator""_sv(const char *data, size_t size) -{ - return APT::StringView(data, size); -} -} - -inline bool operator ==(const char *other, APT::StringView that); -inline bool operator ==(const char *other, APT::StringView that) { return that.operator==(other); } -template<class = void> bool operator ==(std::string_view const &other, APT::StringView const &that) { return that.operator==(other); } -template<class = void> bool operator !=(std::string_view const &other, APT::StringView const &that) { return that.operator!=(other); } -template<class = void> bool operator !=(APT::StringView const &that, std::string_view const &other) { return that.operator!=(other); } -#endif - -#endif diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index 375b5dbd6..e3041f848 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -563,25 +563,6 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, return res; } -#if APT_PKG_ABI <= 600 -const char *debListParser::ParseDepends(const char *Start,const char *Stop, - APT::StringView &Package,APT::StringView &Ver, - unsigned int &Op, bool ParseArchFlags, - bool const StripMultiArch, - bool const ParseRestrictionsList, - string Arch) -{ - string_view PackageView; - string_view VerView; - - auto res = ParseDepends(Start, Stop, PackageView, VerView, Op, (bool)ParseArchFlags, - (bool) StripMultiArch, (bool) ParseRestrictionsList, Arch); - Package = PackageView; - Ver = VerView; - - return res; -} -#endif const char *debListParser::ParseDepends(const char *Start, const char *Stop, string_view &Package, string_view &Ver, diff --git a/apt-pkg/deb/deblistparser.h b/apt-pkg/deb/deblistparser.h index aec09ed2e..27e900790 100644 --- a/apt-pkg/deb/deblistparser.h +++ b/apt-pkg/deb/deblistparser.h @@ -81,15 +81,6 @@ class APT_HIDDEN debListParser : public pkgCacheListParser bool const &ParseRestrictionsList = false, std::string const &Arch = ""); -#if APT_PKG_ABI <= 600 - [[deprecated("Use std::string_view variant instead")]] - APT_PUBLIC static const char *ParseDepends(const char *Start, const char *Stop, - APT::StringView &Package, - APT::StringView &Ver, unsigned int &Op, - bool ParseArchFlags = false, bool StripMultiArch = true, - bool ParseRestrictionsList = false, - std::string Arch = ""); -#endif APT_PUBLIC static const char *ParseDepends(const char *Start, const char *Stop, std::string_view &Package, std::string_view &Ver, unsigned int &Op, diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 3f477b9b1..2beef0e74 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -23,7 +23,6 @@ #include <apt-pkg/aptconfiguration.h> #include <apt-pkg/configuration.h> -#include <apt-pkg/string_view.h> #include <apt-pkg/error.h> #include <apt-pkg/macros.h> #include <apt-pkg/mmap.h> diff --git a/apt-pkg/pkgcachegen.cc b/apt-pkg/pkgcachegen.cc index dd79967c0..8c4a1c517 100644 --- a/apt-pkg/pkgcachegen.cc +++ b/apt-pkg/pkgcachegen.cc @@ -24,7 +24,7 @@ #include <apt-pkg/pkgsystem.h> #include <apt-pkg/progress.h> #include <apt-pkg/sourcelist.h> -#include <apt-pkg/string_view.h> +#include <apt-pkg/strutl.h> #include <apt-pkg/version.h> #include <algorithm> diff --git a/test/libapt/stringview_test.cc b/test/libapt/stringview_test.cc deleted file mode 100644 index 9273534af..000000000 --- a/test/libapt/stringview_test.cc +++ /dev/null @@ -1,99 +0,0 @@ -#include <config.h> -#include <apt-pkg/macros.h> -#include <apt-pkg/string_view.h> -#include <string> - -#include <type_traits> - -#include "common.h" - -#if APT_PKG_ABI <= 600 - -TEST(StringViewTest,EmptyString) -{ - constexpr APT::StringView defString; - static_assert( 0 == defString.length(), "def right size"); - - APT::StringView strString{std::string{}}; - EXPECT_EQ(0u, strString.length()); - - constexpr char const * const charp = ""; - constexpr APT::StringView charpString{charp, 0}; - static_assert( 0 == charpString.length(), "charp right size"); - - APT::StringView charp2String{charp}; - EXPECT_EQ(0u, strString.length()); - - const APT::StringView charaString{""}; - EXPECT_EQ(0u, charaString.length()); - - EXPECT_TRUE(APT::StringView("") == ""); - EXPECT_FALSE(APT::StringView("") != ""); -} - -TEST(StringViewTest,FooString) -{ - constexpr APT::StringView defString("fooGARBAGE", 3); - static_assert( 3 == defString.length(), "def right size"); - EXPECT_EQ(0, defString.to_string().compare(0, defString.length(), defString.data(), 3)); - - std::string strstr{"foo"}; - APT::StringView strString{strstr}; - EXPECT_EQ(3u, strString.length()); - EXPECT_EQ(0, strString.to_string().compare(0, strString.length(), strString.data(), 3)); - - constexpr char const * const charp = "fooGARBAGE"; - constexpr APT::StringView charpString{charp, 3}; - EXPECT_EQ(3u, charpString.length()); - EXPECT_EQ(0, charpString.to_string().compare(0, charpString.length(), charpString.data(), 3)); - - char * charp2 = strdup("foo"); - APT::StringView charp2String{charp2}; - EXPECT_EQ(3u, charp2String.length()); - EXPECT_EQ(0, charp2String.to_string().compare(0, charp2String.length(), charp2String.data(), 3)); - free(charp2); - - const APT::StringView charaString{"foo"}; - EXPECT_EQ(3u, charaString.length()); - EXPECT_EQ(0, charaString.to_string().compare(0, charaString.length(), charaString.data(), 3)); - - EXPECT_TRUE(APT::StringView("foo") == "foo"); - EXPECT_FALSE(APT::StringView("foo") != "foo"); -} - -TEST(StringViewTest,SubStr) -{ - const APT::StringView defString("Hello World!"); - EXPECT_EQ(defString.to_string().substr(6), defString.substr(6).to_string()); - EXPECT_EQ(defString.to_string().substr(0,5), defString.substr(0,5).to_string()); - EXPECT_EQ(defString.to_string().substr(6,5), defString.substr(6,5).to_string()); -} - -TEST(StringViewTest,Find) -{ - const APT::StringView defString("Hello World!"); - EXPECT_EQ(defString.to_string().find('l'), defString.find('l')); - EXPECT_EQ(defString.to_string().find('X'), defString.find('X')); - EXPECT_EQ(defString.to_string().find('e',3), defString.find('e',3)); - EXPECT_EQ(defString.to_string().find('l',6), defString.find('l',6)); - EXPECT_EQ(defString.to_string().find('l',11), defString.find('l',11)); - - EXPECT_EQ(defString.to_string().find("l"), defString.find("l")); - EXPECT_EQ(defString.to_string().find("ll"), defString.find("ll")); - EXPECT_EQ(defString.to_string().find("lo"), defString.find("lo")); - EXPECT_EQ(defString.to_string().find("ll", 1), defString.find("ll", 1)); - EXPECT_EQ(defString.to_string().find("ll", 6), defString.find("ll", 6)); - EXPECT_EQ(defString.to_string().find("or"), defString.find("or")); - EXPECT_EQ(defString.to_string().find("od"), defString.find("od")); -} - -TEST(StringViewTest,RFind) -{ - const APT::StringView defString("Hello World!"); - EXPECT_EQ(defString.to_string().rfind('l'), defString.rfind('l')); - EXPECT_EQ(defString.to_string().rfind('X'), defString.rfind('X')); - EXPECT_EQ(defString.to_string().rfind('e',3), defString.rfind('e',3)); - EXPECT_EQ(defString.to_string().rfind('l',6), defString.rfind('l',6)); - EXPECT_EQ(defString.to_string().rfind('l',11), defString.rfind('l',11)); -} -#endif |
