summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--apt-pkg/tagfile.cc28
-rw-r--r--apt-pkg/tagfile.h22
-rw-r--r--ftparchive/writer.cc4
7 files changed, 79 insertions, 43 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
diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc
index aff786df1..4914ba1b3 100644
--- a/apt-pkg/tagfile.cc
+++ b/apt-pkg/tagfile.cc
@@ -3,10 +3,10 @@
/* ######################################################################
Fast scanner for RFC-822 type header information
-
+
This uses a rotating buffer to load the package information into.
The scanner runs over it and isolates and indexes a single section.
-
+
##################################################################### */
/*}}}*/
// Include Files /*{{{*/
@@ -199,7 +199,7 @@ bool pkgTagFile::Resize(unsigned long long const newSize)
/*}}}*/
// TagFile::Step - Advance to the next section /*{{{*/
// ---------------------------------------------------------------------
-/* If the Section Scanner fails we refill the buffer and try again.
+/* If the Section Scanner fails we refill the buffer and try again.
* If that fails too, double the buffer size and try again until a
* maximum buffer is reached.
*/
@@ -466,14 +466,14 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
if (Tag.Scan(d->Start, d->End - d->Start) == true)
return true;
-
+
// This appends a double new line (for the real eof handling)
if (Fill() == false)
return false;
-
+
if (Tag.Scan(d->Start, d->End - d->Start, false) == false)
return _error->Error(_("Unable to parse package file %s (%d)"),d->Fd->Name().c_str(), 2);
-
+
return true;
}
/*}}}*/
@@ -602,7 +602,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength, bool const R
TrimRecord(false,End);
return true;
}
-
+
Stop++;
}
@@ -814,7 +814,7 @@ unsigned long long pkgTagSection::FindULLInternal(unsigned int Pos, unsigned lon
return Default;
strncpy(S,Start,Stop-Start);
S[Stop - Start] = 0;
-
+
char *End;
unsigned long long Result = strtoull(S,&End,10);
if (S == End)
@@ -959,15 +959,27 @@ APT_PURE unsigned int pkgTagSection::Count() const { /*{{{*/
}
/*}}}*/
// TagSection::Write - Ordered (re)writing of fields /*{{{*/
+#if APT_PKG_ABI > 600
+pkgTagSection::Tag pkgTagSection::Tag::Remove(std::string_view Name)
+#else
pkgTagSection::Tag pkgTagSection::Tag::Remove(std::string const &Name)
+#endif
{
return Tag(REMOVE, Name, "");
}
+#if APT_PKG_ABI > 600
+pkgTagSection::Tag pkgTagSection::Tag::Rename(std::string_view OldName, std::string_view NewName)
+#else
pkgTagSection::Tag pkgTagSection::Tag::Rename(std::string const &OldName, std::string const &NewName)
+#endif
{
return Tag(RENAME, OldName, NewName);
}
+#if APT_PKG_ABI > 600
+pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string_view Name, std::string_view Data)
+#else
pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::string const &Data)
+#endif
{
if (Data.empty() == true)
return Tag(REMOVE, Name, "");
diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h
index 60fca09c1..b32317cec 100644
--- a/apt-pkg/tagfile.h
+++ b/apt-pkg/tagfile.h
@@ -3,17 +3,17 @@
/* ######################################################################
Fast scanner for RFC-822 type header information
-
+
This parser handles Debian package files (and others). Their form is
RFC-822 type header fields in groups separated by a blank line.
-
+
The parser reads the file and provides methods to step linearly
over it or to jump to a pre-recorded start point and read that record.
-
+
A second class is used to perform pre-parsing of the record. It works
- by indexing the start of each header field and providing lookup
+ by indexing the start of each header field and providing lookup
functions for header fields.
-
+
##################################################################### */
/*}}}*/
#ifndef PKGLIB_TAGFILE_H
@@ -67,8 +67,8 @@ class APT_PUBLIC pkgTagSection
inline bool operator !=(const pkgTagSection &rhs) {return Section != rhs.Section;};
// TODO: Remove internally
- std::string FindS(APT::StringView sv) const { return Find(sv).to_string(); }
- std::string FindRawS(APT::StringView sv) const { return FindRaw(sv).to_string(); };
+ std::string FindS(APT::StringView sv) const { return std::string{Find(sv)}; }
+ std::string FindRawS(APT::StringView sv) const { return std::string{FindRaw(sv)}; };
// Functions for lookup with a perfect hash function
enum class Key;
@@ -150,11 +150,17 @@ class APT_PUBLIC pkgTagSection
std::string Name;
std::string Data;
+#if APT_PKG_ABI > 600
+ static Tag Remove(std::string_view Name);
+ static Tag Rename(std::string_view OldName, std::string_view NewName);
+ static Tag Rewrite(std::string_view Name, std::string_view Data);
+#else
static Tag Remove(std::string const &Name);
static Tag Rename(std::string const &OldName, std::string const &NewName);
static Tag Rewrite(std::string const &Name, std::string const &Data);
+#endif
private:
- Tag(ActionType const Action, std::string const &Name, std::string const &Data) :
+ Tag(ActionType const Action, std::string_view Name, std::string_view Data) :
Action(Action), Name(Name), Data(Data) {}
};
diff --git a/ftparchive/writer.cc b/ftparchive/writer.cc
index 6d2a13314..dcae84b86 100644
--- a/ftparchive/writer.cc
+++ b/ftparchive/writer.cc
@@ -829,7 +829,11 @@ bool SourcesWriter::DoPackage(string FileName)
std::vector<pkgTagSection::Tag> Changes;
Changes.push_back(pkgTagSection::Tag::Remove("Source"));
+#if APT_PKG_ABI > 600
+ Changes.push_back(pkgTagSection::Tag::Rewrite("Package", Package));
+#else
Changes.push_back(pkgTagSection::Tag::Rewrite("Package", std::string{Package}));
+#endif
if (Files.empty() == false)
Changes.push_back(pkgTagSection::Tag::Rewrite("Files", Files));
else