summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/hashes.cc12
-rw-r--r--apt-pkg/contrib/hashes.h13
-rw-r--r--apt-pkg/contrib/string_view.h17
-rw-r--r--apt-pkg/contrib/strutl.h26
4 files changed, 41 insertions, 27 deletions
diff --git a/apt-pkg/contrib/hashes.cc b/apt-pkg/contrib/hashes.cc
index 0ad51fff0..06bfd003e 100644
--- a/apt-pkg/contrib/hashes.cc
+++ b/apt-pkg/contrib/hashes.cc
@@ -3,10 +3,10 @@
/* ######################################################################
Hashes - Simple wrapper around the hash functions
-
+
This is just used to make building the methods simpler, this is the
only interface required..
-
+
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
@@ -66,7 +66,11 @@ HashString::HashString(std::string Type, std::string Hash) : Type(Type), Hash(Ha
{
}
-HashString::HashString(std::string StringedHash) /*{{{*/
+#if APT_PKG_ABI > 600
+HashString::HashString(std::string_view StringedHash) /*{{{*/
+#else
+HashString::HashString(std::string StringedHash) /*{{{*/
+#endif
{
if (StringedHash.find(":") == std::string::npos)
{
@@ -80,7 +84,7 @@ HashString::HashString(std::string StringedHash) /*{{{*/
std::clog << "HashString(string): invalid StringedHash " << StringedHash << std::endl;
return;
}
- std::string::size_type pos = StringedHash.find(":");
+ auto pos = StringedHash.find(":");
Type = StringedHash.substr(0,pos);
Hash = StringedHash.substr(pos+1, StringedHash.size() - pos);
diff --git a/apt-pkg/contrib/hashes.h b/apt-pkg/contrib/hashes.h
index e259b4e28..69b742f10 100644
--- a/apt-pkg/contrib/hashes.h
+++ b/apt-pkg/contrib/hashes.h
@@ -3,10 +3,10 @@
/* ######################################################################
Hashes - Simple wrapper around the hash functions
-
+
This is just used to make building the methods simpler, this is the
only interface required..
-
+
##################################################################### */
/*}}}*/
#ifndef APTPKG_HASHES_H
@@ -15,7 +15,6 @@
#include <apt-pkg/macros.h>
#ifdef APT_COMPILING_APT
-#include <apt-pkg/string_view.h>
#include <apt-pkg/tagfile-keys.h>
#endif
@@ -41,7 +40,11 @@ class APT_PUBLIC HashString
public:
HashString(std::string Type, std::string Hash);
+#if APT_PKG_ABI > 600
+ explicit HashString(std::string_view StringedHashString); // init from str as "type:hash"
+#else
explicit HashString(std::string StringedHashString); // init from str as "type:hash"
+#endif
HashString();
// get hash type used
@@ -66,9 +69,9 @@ class APT_PUBLIC HashString
static APT_PURE const char** SupportedHashes();
#ifdef APT_COMPILING_APT
struct APT_HIDDEN HashSupportInfo {
- APT::StringView name;
+ std::string_view name;
pkgTagSection::Key namekey;
- APT::StringView chksumsname;
+ std::string_view chksumsname;
pkgTagSection::Key chksumskey;
};
APT_HIDDEN static std::vector<HashSupportInfo> SupportedHashesInfo();
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h
index b062517b6..6224e2ac4 100644
--- a/apt-pkg/contrib/string_view.h
+++ b/apt-pkg/contrib/string_view.h
@@ -15,6 +15,11 @@
#include <cstring>
#include <string>
+#if APT_PKG_ABI > 600
+namespace APT {
+using StringView = std::string_view;
+}
+#else
namespace APT {
/**
@@ -146,17 +151,6 @@ inline std::ostream& operator<<(std::ostream& os, const StringView& sv)
return os << static_cast<std::string_view>(sv);
}
-/**
- * \brief Faster comparison for string views (compare size before data)
- *
- * Still stable, but faster than the normal ordering. */
-static inline int StringViewCompareFast(const std::string_view & a, const std::string_view & b) {
- if (a.size() != b.size())
- return a.size() - b.size();
-
- return a.compare(b);
-}
-
static constexpr inline APT::StringView operator""_sv(const char *data, size_t size)
{
return APT::StringView(data, size);
@@ -168,5 +162,6 @@ inline bool operator ==(const char *other, APT::StringView that) { return that.o
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/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 152477eee..90d9674fd 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -4,16 +4,16 @@
/* ######################################################################
String Util - These are some useful string functions
-
+
_strstrip is a function to remove whitespace from the front and end
of a string.
-
+
This file had this historic note, but now includes further changes
under the GPL-2.0+:
This source is placed in the Public Domain, do with it what you will
- It was originally written by Jason Gunthorpe <jgg@gpu.srv.ualberta.ca>
-
+ It was originally written by Jason Gunthorpe <jgg@gpu.srv.ualberta.ca>
+
##################################################################### */
/*}}}*/
#ifndef STRUTL_H
@@ -26,6 +26,7 @@
#include <iostream>
#include <limits>
#include <string>
+#include <string_view>
#include <vector>
#include "macros.h"
@@ -121,13 +122,13 @@ APT_PUBLIC std::vector<std::string> VectorizeString(std::string const &haystack,
*
* \param maxsplit (optional) The maximum amount of splitting that
* should be done .
- *
+ *
* The optional "maxsplit" argument can be used to limit the splitting,
* if used the string is only split on maxsplit places and the last
* item in the vector contains the remainder string.
*/
APT_PUBLIC std::vector<std::string> StringSplit(std::string const &input,
- std::string const &sep,
+ std::string const &sep,
unsigned int maxsplit=std::numeric_limits<unsigned int>::max()) APT_PURE;
@@ -229,7 +230,7 @@ class APT_PUBLIC URI
std::string Host;
std::string Path;
unsigned int Port;
-
+
operator std::string();
inline void operator =(const std::string &From) {CopyFrom(From);}
inline bool empty() {return Access.empty();};
@@ -258,4 +259,15 @@ struct RxChoiceList
APT_PUBLIC unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin,
const char **ListEnd);
+/**
+ * \brief Faster comparison for string views (compare size before data)
+ *
+ * Still stable, but faster than the normal ordering. */
+static inline int StringViewCompareFast(const std::string_view & a, const std::string_view & b) {
+ if (a.size() != b.size())
+ return a.size() - b.size();
+
+ return a.compare(b);
+}
+
#endif