From 793c9b1f3059c35b66c19f62fa39b6607809fea0 Mon Sep 17 00:00:00 2001 From: наб Date: Tue, 12 Nov 2024 17:59:18 +0100 Subject: APT::StringView -> std::string_view [textonly] --- apt-pkg/cachefilter-patterns.cc | 2 +- apt-pkg/cachefilter.h | 2 +- apt-pkg/cacheiterators.h | 17 ++++---- apt-pkg/contrib/strutl.cc | 6 +-- apt-pkg/contrib/strutl.h | 5 +-- apt-pkg/deb/deblistparser.cc | 8 ++-- apt-pkg/depcache.h | 6 +-- apt-pkg/pkgcache.cc | 89 +++++++++++++++++++++-------------------- apt-pkg/pkgcache.h | 17 ++++---- apt-pkg/tagfile.cc | 41 +++++++++---------- apt-pkg/tagfile.h | 33 ++++++++------- 11 files changed, 111 insertions(+), 115 deletions(-) (limited to 'apt-pkg') diff --git a/apt-pkg/cachefilter-patterns.cc b/apt-pkg/cachefilter-patterns.cc index 838c71a81..e79e1afb5 100644 --- a/apt-pkg/cachefilter-patterns.cc +++ b/apt-pkg/cachefilter-patterns.cc @@ -588,7 +588,7 @@ BaseRegexMatcher::~BaseRegexMatcher() } // namespace Internal // The bridge into the public world -std::unique_ptr APT::CacheFilter::ParsePattern(APT::StringView pattern, pkgCacheFile *file) +std::unique_ptr APT::CacheFilter::ParsePattern(std::string_view pattern, pkgCacheFile *file) { if (file != nullptr && !file->BuildDepCache()) return nullptr; diff --git a/apt-pkg/cachefilter.h b/apt-pkg/cachefilter.h index 6d5858b28..8678be5df 100644 --- a/apt-pkg/cachefilter.h +++ b/apt-pkg/cachefilter.h @@ -149,7 +149,7 @@ public: /*}}}*/ /// \brief Parse a pattern, return nullptr or pattern -APT_PUBLIC std::unique_ptr ParsePattern(APT::StringView pattern, pkgCacheFile *file); +APT_PUBLIC std::unique_ptr ParsePattern(std::string_view pattern, pkgCacheFile *file); } } #endif diff --git a/apt-pkg/cacheiterators.h b/apt-pkg/cacheiterators.h index 38b4b8635..ceeb4b3a7 100644 --- a/apt-pkg/cacheiterators.h +++ b/apt-pkg/cacheiterators.h @@ -1,17 +1,17 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ /* ###################################################################### - + Cache Iterators - Iterators for navigating the cache structure - + The iterators all provides ++,==,!=,->,* and end for their type. The end function can be used to tell if the list has been fully traversed. - + Unlike STL iterators these contain helper functions to access the data that is being iterated over. This is because the data structures can't be formed in a manner that is intuitive to use and also mmapable. - + For each variable in the target structure that would need a translation to be accessed correctly a translating function of the same name is present in the iterator. If applicable the translating function will @@ -22,9 +22,9 @@ structure passed to the constructor, which should be the structure that has the depends pointer as a member. The provide iterator has the same system. - + This header is not user includable, please use apt-pkg/pkgcache.h - + ##################################################################### */ /*}}}*/ #ifndef PKGLIB_CACHEITERATORS_H @@ -37,7 +37,6 @@ #include #include #include -#include #include @@ -123,7 +122,7 @@ class APT_PUBLIC pkgCache::GrpIterator: public Iterator { inline const char *Name() const {return S->Name == 0?0:Owner->StrP + S->Name;} inline PkgIterator PackageList() const; inline VerIterator VersionsInSource() const; - PkgIterator FindPkg(APT::StringView Arch = APT::StringView("any", 3)) const; + PkgIterator FindPkg(std::string_view Arch = {"any", 3}) const; /** \brief find the package with the "best" architecture The best architecture is either the "native" or the first @@ -234,7 +233,7 @@ class APT_PUBLIC pkgCache::VerIterator : public Iterator { inline PkgIterator ParentPkg() const {return PkgIterator(*Owner,Owner->PkgP + S->ParentPkg);} inline DescIterator DescriptionList() const; - DescIterator TranslatedDescriptionForLanguage(APT::StringView lang) const; + DescIterator TranslatedDescriptionForLanguage(std::string_view lang) const; DescIterator TranslatedDescription() const; inline DepIterator DependsList() const; inline PrvIterator ProvidesList() const; diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 69a67188e..5d91e5f11 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -104,7 +104,7 @@ std::string Join(std::vector list, const std::string &sep) } // Returns string display length honoring multi-byte characters -size_t DisplayLength(StringView str) +size_t DisplayLength(string_view str) { size_t len = 0; @@ -930,7 +930,7 @@ string TimeRFC1123(time_t Date, bool const NumericTimezone) auto const posix = std::locale::classic(); std::ostringstream datestr; datestr.imbue(posix); - APT::StringView const fmt("%a, %d %b %Y %H:%M:%S"); + std::string_view const fmt("%a, %d %b %Y %H:%M:%S"); std::use_facet>(posix).put( std::ostreambuf_iterator(datestr), datestr, ' ', &Conv, fmt.data(), fmt.data() + fmt.size()); @@ -1307,7 +1307,7 @@ static int HexDigit(int c) // Hex2Num - Convert a long hex number into a buffer /*{{{*/ // --------------------------------------------------------------------- /* The length of the buffer must be exactly 1/2 the length of the string. */ -bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length) +bool Hex2Num(const std::string_view Str,unsigned char *Num,unsigned int Length) { if (Str.length() != Length*2) return false; diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index fdaa23766..9db908c7f 100644 --- a/apt-pkg/contrib/strutl.h +++ b/apt-pkg/contrib/strutl.h @@ -19,7 +19,6 @@ #ifndef STRUTL_H #define STRUTL_H -#include #include #include #include @@ -48,7 +47,7 @@ namespace APT { APT_PUBLIC bool Startswith(const std::string &s, const std::string &starting); APT_PUBLIC std::string Join(std::vector list, const std::string &sep); // Returns string display length honoring multi-byte characters - APT_PUBLIC size_t DisplayLength(StringView str); + APT_PUBLIC size_t DisplayLength(std::string_view str); } } @@ -106,7 +105,7 @@ APT_PUBLIC bool StrToNum(const char *Str,unsigned long &Res,unsigned Len,unsigne APT_PUBLIC bool StrToNum(const char *Str,unsigned long long &Res,unsigned Len,unsigned Base = 0); APT_PUBLIC bool Base256ToNum(const char *Str,unsigned long &Res,unsigned int Len); APT_PUBLIC bool Base256ToNum(const char *Str,unsigned long long &Res,unsigned int Len); -APT_PUBLIC bool Hex2Num(const APT::StringView Str,unsigned char *Num,unsigned int Length); +APT_PUBLIC bool Hex2Num(const std::string_view Str,unsigned char *Num,unsigned int Length); // input changing string split APT_PUBLIC bool TokSplitString(char Tok,char *Input,char **List, unsigned long ListMax); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index db3478f53..375b5dbd6 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -120,9 +120,9 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ { unsigned char MA; auto const MultiArch = Section.Find(pkgTagSection::Key::Multi_Arch); - if (MultiArch.empty() == true || MultiArch == "no") + if (MultiArch.empty() == true || MultiArch == "no"sv) MA = pkgCache::Version::No; - else if (MultiArch == "same") { + else if (MultiArch == "same"sv) { if (ArchitectureAll() == true) { if (showErrors == true) @@ -133,9 +133,9 @@ unsigned char debListParser::ParseMultiArch(bool const showErrors) /*{{{*/ else MA = pkgCache::Version::Same; } - else if (MultiArch == "foreign") + else if (MultiArch == "foreign"sv) MA = pkgCache::Version::Foreign; - else if (MultiArch == "allowed") + else if (MultiArch == "allowed"sv) MA = pkgCache::Version::Allowed; else { diff --git a/apt-pkg/depcache.h b/apt-pkg/depcache.h index 8d50d6fc6..665f8e86b 100644 --- a/apt-pkg/depcache.h +++ b/apt-pkg/depcache.h @@ -332,9 +332,9 @@ class APT_PUBLIC pkgDepCache : protected pkgCache::Namespace inline Header &Head() {return *Cache->HeaderP;}; inline GrpIterator GrpBegin() {return Cache->GrpBegin();}; inline PkgIterator PkgBegin() {return Cache->PkgBegin();}; - inline GrpIterator FindGrp(APT::StringView Name) {return Cache->FindGrp(Name);}; - inline PkgIterator FindPkg(APT::StringView Name) {return Cache->FindPkg(Name);}; - inline PkgIterator FindPkg(APT::StringView Name, APT::StringView Arch) {return Cache->FindPkg(Name, Arch);}; + inline GrpIterator FindGrp(std::string_view Name) {return Cache->FindGrp(Name);}; + inline PkgIterator FindPkg(std::string_view Name) {return Cache->FindPkg(Name);}; + inline PkgIterator FindPkg(std::string_view Name, std::string_view Arch) {return Cache->FindPkg(Name, Arch);}; inline pkgCache &GetCache() {return *Cache;}; inline pkgVersioningSystem &VS() {return *Cache->VS;}; diff --git a/apt-pkg/pkgcache.cc b/apt-pkg/pkgcache.cc index 1f1aadf59..3f477b9b1 100644 --- a/apt-pkg/pkgcache.cc +++ b/apt-pkg/pkgcache.cc @@ -1,18 +1,18 @@ // -*- mode: cpp; mode: fold -*- // Description /*{{{*/ /* ###################################################################### - + Package Cache - Accessor code for the cache - - Please see doc/apt-pkg/cache.sgml for a more detailed description of + + Please see doc/apt-pkg/cache.sgml for a more detailed description of this format. Also be sure to keep that file up-to-date!! - + This is the general utility functions for cache management. They provide a complete set of accessor functions for the cache. The cacheiterators header contains the STL-like iterators that can be used to easially navigate the cache as well as seamlessly dereference the mmap'd indexes. Use these always. - + The main class provides for ways to get package indexes and some general lookup functions to start the iterators. @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -45,7 +46,7 @@ /*}}}*/ using std::string; -using APT::StringView; +using std::string_view; // Cache::Header::Header - Constructor /*{{{*/ @@ -128,7 +129,7 @@ bool pkgCache::Header::CheckSizes(Header &Against) const /* */ pkgCache::pkgCache(MMap *Map, bool DoMap) : Map(*Map), VS(nullptr), d(NULL) { - // call getArchitectures() with cached=false to ensure that the + // call getArchitectures() with cached=false to ensure that the // architectures cache is re-evaluated. this is needed in cases // when the APT::Architecture field changes between two cache creations APT::Configuration::getArchitectures(false); @@ -162,13 +163,13 @@ bool pkgCache::ReMap(bool const &Errorchecks) if (Map.Size() == 0 || HeaderP == 0) return _error->Error(_("Empty package cache")); - + // Check the header Header DefHeader; if (HeaderP->Signature != DefHeader.Signature || HeaderP->Dirty == true) return _error->Error(_("The package cache file is corrupted")); - + if (HeaderP->MajorVersion != DefHeader.MajorVersion || HeaderP->MinorVersion != DefHeader.MinorVersion || HeaderP->CheckSizes(DefHeader) == false) @@ -208,7 +209,7 @@ bool pkgCache::ReMap(bool const &Errorchecks) /* This is used to generate the hash entries for the HashTable. With my package list from bo this function gets 94% table usage on a 512 item table (480 used items) */ -map_id_t pkgCache::sHash(StringView Str) const +map_id_t pkgCache::sHash(string_view Str) const { uint32_t Hash = 5381; auto I = Str.begin(); @@ -265,7 +266,7 @@ uint32_t pkgCache::CacheHash() // Cache::FindPkg - Locate a package by name /*{{{*/ // --------------------------------------------------------------------- /* Returns 0 on error, pointer to the package otherwise */ -pkgCache::PkgIterator pkgCache::FindPkg(StringView Name) { +pkgCache::PkgIterator pkgCache::FindPkg(string_view Name) { auto const found = Name.rfind(':'); if (found == string::npos) return FindPkg(Name, "native"); @@ -281,7 +282,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(StringView Name) { // Cache::FindPkg - Locate a package by name /*{{{*/ // --------------------------------------------------------------------- /* Returns 0 on error, pointer to the package otherwise */ -pkgCache::PkgIterator pkgCache::FindPkg(StringView Name, StringView Arch) { +pkgCache::PkgIterator pkgCache::FindPkg(string_view Name, string_view Arch) { /* We make a detour via the GrpIterator here as on a multi-arch environment a group is easier to find than a package (less entries in the buckets) */ @@ -295,7 +296,7 @@ pkgCache::PkgIterator pkgCache::FindPkg(StringView Name, StringView Arch) { // Cache::FindGrp - Locate a group by name /*{{{*/ // --------------------------------------------------------------------- /* Returns End-Pointer on error, pointer to the group otherwise */ -pkgCache::GrpIterator pkgCache::FindGrp(StringView Name) { +pkgCache::GrpIterator pkgCache::FindGrp(string_view Name) { if (unlikely(Name.empty() == true)) return GrpIterator(*this,0); @@ -314,7 +315,7 @@ pkgCache::GrpIterator pkgCache::FindGrp(StringView Name) { /*}}}*/ // Cache::CompTypeDeb - Return a string describing the compare type /*{{{*/ // --------------------------------------------------------------------- -/* This returns a string representation of the dependency compare +/* This returns a string representation of the dependency compare type in the weird debian style.. */ const char *pkgCache::CompTypeDeb(unsigned char Comp) { @@ -380,7 +381,7 @@ std::string_view pkgCache::Priority_NoL10n(unsigned char Prio) // GrpIterator::FindPkg - Locate a package by arch /*{{{*/ // --------------------------------------------------------------------- /* Returns an End-Pointer on error, pointer to the package otherwise */ -pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(StringView Arch) const { +pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(string_view Arch) const { if (unlikely(IsGood() == false || S->FirstPackage == 0)) return PkgIterator(*Owner, 0); @@ -407,7 +408,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPkg(StringView Arch) const { // --------------------------------------------------------------------- /* Returns an End-Pointer on error, pointer to the package otherwise */ pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg(bool const &PreferNonVirtual) const { - pkgCache::PkgIterator Pkg = FindPkg(StringView("native", 6)); + pkgCache::PkgIterator Pkg = FindPkg(string_view("native", 6)); if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) return Pkg; // native and foreign @@ -425,7 +426,7 @@ pkgCache::PkgIterator pkgCache::GrpIterator::FindPreferredPkg(bool const &Prefer return Pkg; } // packages without an architecture - Pkg = FindPkg(StringView("none", 4)); + Pkg = FindPkg(string_view("none", 4)); if (Pkg.end() == false && (PreferNonVirtual == false || Pkg->VersionList != 0)) return Pkg; // the "rest" we somehow know about (+ those we tried already again as skipping is hard) @@ -506,25 +507,25 @@ pkgCache::DepIterator& pkgCache::DepIterator::operator++() /*{{{*/ // --------------------------------------------------------------------- /* By this we mean if it is either cleanly installed or cleanly removed. */ pkgCache::PkgIterator::OkState pkgCache::PkgIterator::State() const -{ +{ if (S->InstState == pkgCache::State::ReInstReq || S->InstState == pkgCache::State::HoldReInstReq) return NeedsUnpack; - + if (S->CurrentState == pkgCache::State::UnPacked || S->CurrentState == pkgCache::State::HalfConfigured) // we leave triggers alone completely. dpkg deals with - // them in a hard-to-predict manner and if they get - // resolved by dpkg before apt run dpkg --configure on + // them in a hard-to-predict manner and if they get + // resolved by dpkg before apt run dpkg --configure on // the TriggersPending package dpkg returns a error //Pkg->CurrentState == pkgCache::State::TriggersAwaited //Pkg->CurrentState == pkgCache::State::TriggersPending) return NeedsConfigure; - + if (S->CurrentState == pkgCache::State::HalfInstalled || S->InstState != pkgCache::State::Ok) return NeedsUnpack; - + return NeedsNothing; } /*}}}*/ @@ -546,8 +547,8 @@ pkgCache::PkgIterator::CurVersion() const Note that the characters <|>() are all literal above. Versions will be omitted if they provide no new information (e.g. there is no newer version than candidate) If no version and/or section can be found "none" is used. */ -std::ostream& -operator<<(std::ostream& out, pkgCache::PkgIterator Pkg) +std::ostream& +operator<<(std::ostream& out, pkgCache::PkgIterator Pkg) { if (Pkg.end() == true) return out << "invalid package"; @@ -610,34 +611,34 @@ bool pkgCache::DepIterator::IsNegative() const then it returned. Otherwise the providing list is looked at to see if there is one unique providing package if so it is returned. Otherwise true is returned and the target package is set. The return - result indicates whether the node should be expandable - - In Conjunction with the DepCache the value of Result may not be + result indicates whether the node should be expandable + + In Conjunction with the DepCache the value of Result may not be super-good since the policy may have made it uninstallable. Using AllTargets is better in this case. */ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const { Result = TargetPkg(); - + // No provides at all if (Result->ProvidesList == 0) return false; - + // There is the Base package and the providing ones which is at least 2 if (Result->VersionList != 0) return true; - + /* We have to skip over indirect provisions of the package that owns the dependency. For instance, if libc5-dev depends on the virtual package libc-dev which is provided by libc5-dev and libc6-dev - we must ignore libc5-dev when considering the provides list. */ + we must ignore libc5-dev when considering the provides list. */ PrvIterator PStart = Result.ProvidesList(); for (; PStart.end() != true && PStart.OwnerPkg() == ParentPkg(); ++PStart); // Nothing but indirect self provides if (PStart.end() == true) return false; - + // Check for single packages in the provides list PrvIterator P = PStart; for (; P.end() != true; ++P) @@ -650,11 +651,11 @@ bool pkgCache::DepIterator::SmartTargetPkg(PkgIterator &Result) const } Result = PStart.OwnerPkg(); - + // Check for non dups if (P.end() != true) return true; - + return false; } /*}}}*/ @@ -685,7 +686,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const if (Res != 0) *End++ = I; } - + // Follow all provides for (PrvIterator I = DPkg.ProvidesList(); I.end() == false; ++I) { @@ -698,7 +699,7 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const if (Res != 0) *End++ = I.OwnerVer(); } - + // Do it again and write it into the array if (Res == 0) { @@ -709,9 +710,9 @@ pkgCache::Version **pkgCache::DepIterator::AllTargets() const { *End = 0; break; - } + } } - + return Res; } /*}}}*/ @@ -845,7 +846,7 @@ int pkgCache::VerIterator::CompareVer(const VerIterator &B) const return -1; if (B.end() == true) return 1; - + /* Start at A and look for B. If B is found then A > B otherwise B was before A so A < B */ VerIterator I = *this; @@ -869,7 +870,7 @@ APT_PURE bool pkgCache::VerIterator::Downloadable() const /*}}}*/ // VerIterator::Automatic - Check if this version is 'automatic' /*{{{*/ // --------------------------------------------------------------------- -/* This checks to see if any of the versions files are not NotAutomatic. +/* This checks to see if any of the versions files are not NotAutomatic. True if this version is selectable for automatic installation. */ APT_PURE bool pkgCache::VerIterator::Automatic() const { @@ -894,13 +895,13 @@ pkgCache::VerFileIterator pkgCache::VerIterator::NewestFile() const if (Owner->VS->CmpReleaseVer(Files.File().Version(),Highest.File().Version()) > 0) Highest = Files; } - + return Highest; } /*}}}*/ // VerIterator::RelStr - Release description string /*{{{*/ // --------------------------------------------------------------------- -/* This describes the version from a release-centric manner. The output is a +/* This describes the version from a release-centric manner. The output is a list of Label:Version/Archive */ static std::string PkgFileIteratorToRelString(pkgCache::PkgFileIterator const &File) { @@ -1004,7 +1005,7 @@ string pkgCache::PkgFileIterator::RelStr() /*{{{*/ // --------------------------------------------------------------------- /* return a DescIter for the specified language */ -pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescriptionForLanguage(StringView lang) const +pkgCache::DescIterator pkgCache::VerIterator::TranslatedDescriptionForLanguage(string_view lang) const { for (pkgCache::DescIterator Desc = DescriptionList(); Desc.end() == false; ++Desc) if (lang == Desc.LanguageCode()) diff --git a/apt-pkg/pkgcache.h b/apt-pkg/pkgcache.h index 0b61b0048..ed445b5bc 100644 --- a/apt-pkg/pkgcache.h +++ b/apt-pkg/pkgcache.h @@ -82,7 +82,6 @@ #include #include -#include // size of (potentially big) files like debs or the install size of them @@ -213,7 +212,7 @@ class APT_PUBLIC pkgCache /*{{{*/ // Memory mapped cache file std::string CacheFile; MMap ⤅ - map_id_t sHash(APT::StringView S) const APT_PURE; + map_id_t sHash(std::string_view S) const APT_PURE; public: @@ -239,7 +238,7 @@ class APT_PUBLIC pkgCache /*{{{*/ inline void *DataEnd() {return ((unsigned char *)Map.Data()) + Map.Size();} // String hashing function (512 range) - inline map_id_t Hash(APT::StringView S) const {return sHash(S);} + inline map_id_t Hash(std::string_view S) const {return sHash(S);} APT_HIDDEN uint32_t CacheHash(); @@ -248,15 +247,15 @@ class APT_PUBLIC pkgCache /*{{{*/ static std::string_view Priority_NoL10n(unsigned char Prio); // Accessors - GrpIterator FindGrp(APT::StringView Name); - PkgIterator FindPkg(APT::StringView Name); - PkgIterator FindPkg(APT::StringView Name, APT::StringView Arch); + GrpIterator FindGrp(std::string_view Name); + PkgIterator FindPkg(std::string_view Name); + PkgIterator FindPkg(std::string_view Name, std::string_view Arch); - APT::StringView ViewString(map_stringitem_t idx) const + std::string_view ViewString(map_stringitem_t idx) const { char *name = StrP + idx; - uint16_t len = *reinterpret_cast(name - sizeof(uint16_t)); - return APT::StringView(name, len); + size_t len = *reinterpret_cast(name - sizeof(uint16_t)); + return {name, len}; } Header &Head() {return *HeaderP;} diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 45d919673..bb0244cd5 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include @@ -31,9 +30,9 @@ #include /*}}}*/ -using APT::StringView; using APT::Configuration::color; using std::string; +using std::string_view; class APT_HIDDEN pkgTagFilePrivate /*{{{*/ { @@ -628,7 +627,7 @@ void pkgTagSection::Trim() } /*}}}*/ // TagSection::Exists - return True if a tag exists /*{{{*/ -bool pkgTagSection::Exists(StringView Tag) const +bool pkgTagSection::Exists(string_view Tag) const { unsigned int tmp; return Find(Tag, tmp); @@ -648,7 +647,7 @@ bool pkgTagSection::Find(Key key,unsigned int &Pos) const Pos = Bucket - 1; return Bucket != 0; } -bool pkgTagSection::Find(StringView TagView,unsigned int &Pos) const +bool pkgTagSection::Find(string_view TagView,unsigned int &Pos) const { const char * const Tag = TagView.data(); size_t const Length = TagView.length(); @@ -693,7 +692,7 @@ bool pkgTagSection::FindInternal(unsigned int Pos, const char *&Start, return true; } -bool pkgTagSection::Find(StringView Tag,const char *&Start, +bool pkgTagSection::Find(string_view Tag,const char *&Start, const char *&End) const { unsigned int Pos; @@ -707,25 +706,25 @@ bool pkgTagSection::Find(Key key,const char *&Start, } /*}}}*/ // TagSection::FindS - Find a string /*{{{*/ -StringView pkgTagSection::Find(StringView Tag) const +string_view pkgTagSection::Find(string_view Tag) const { const char *Start; const char *End; if (Find(Tag,Start,End) == false) - return StringView(); - return StringView(Start, End - Start); + return string_view(); + return string_view(Start, End - Start); } -StringView pkgTagSection::Find(Key key) const +string_view pkgTagSection::Find(Key key) const { const char *Start; const char *End; if (Find(key,Start,End) == false) - return StringView(); - return StringView(Start, End - Start); + return string_view(); + return string_view(Start, End - Start); } /*}}}*/ // TagSection::FindRawS - Find a string /*{{{*/ -StringView pkgTagSection::FindRawInternal(unsigned int Pos) const +string_view pkgTagSection::FindRawInternal(unsigned int Pos) const { if (unlikely(Pos + 1 >= d->Tags.size() || Pos >= d->Tags.size())) return _error->Error("Internal parsing error"), ""; @@ -743,14 +742,14 @@ StringView pkgTagSection::FindRawInternal(unsigned int Pos) const for (; isspace_ascii(End[-1]) != 0 && End > Start; --End); - return StringView(Start, End - Start); + return string_view(Start, End - Start); } -StringView pkgTagSection::FindRaw(StringView Tag) const +string_view pkgTagSection::FindRaw(std::string_view Tag) const { unsigned int Pos; return Find(Tag, Pos) ? FindRawInternal(Pos) : ""; } -StringView pkgTagSection::FindRaw(Key key) const +string_view pkgTagSection::FindRaw(Key key) const { unsigned int Pos; return Find(key, Pos) ? FindRawInternal(Pos) : ""; @@ -791,7 +790,7 @@ signed int pkgTagSection::FindI(Key key,signed long Default) const return Find(key, Pos) ? FindIInternal(Pos) : Default; } -signed int pkgTagSection::FindI(StringView Tag,signed long Default) const +signed int pkgTagSection::FindI(string_view Tag,signed long Default) const { unsigned int Pos; @@ -827,7 +826,7 @@ unsigned long long pkgTagSection::FindULL(Key key, unsigned long long const &Def return Find(key, Pos) ? FindULLInternal(Pos, Default) : Default; } -unsigned long long pkgTagSection::FindULL(StringView Tag, unsigned long long const &Default) const +unsigned long long pkgTagSection::FindULL(string_view Tag, unsigned long long const &Default) const { unsigned int Pos; @@ -849,7 +848,7 @@ bool pkgTagSection::FindB(Key key, bool Default) const unsigned int Pos; return Find(key, Pos) ? FindBInternal(Pos, Default): Default; } -bool pkgTagSection::FindB(StringView Tag, bool Default) const +bool pkgTagSection::FindB(string_view Tag, bool Default) const { unsigned int Pos; return Find(Tag, Pos) ? FindBInternal(Pos, Default) : Default; @@ -875,7 +874,7 @@ bool pkgTagSection::FindFlag(Key key, uint8_t &Flags, return true; return FindFlagInternal(Pos, Flags, Flag); } -bool pkgTagSection::FindFlag(StringView Tag, uint8_t &Flags, +bool pkgTagSection::FindFlag(string_view Tag, uint8_t &Flags, uint8_t const Flag) const { unsigned int Pos; @@ -917,7 +916,7 @@ bool pkgTagSection::FindFlag(Key key,unsigned long &Flags, unsigned int Pos; return Find(key, Pos) ? FindFlagInternal(Pos, Flags, Flag) : true; } -bool pkgTagSection::FindFlag(StringView Tag,unsigned long &Flags, +bool pkgTagSection::FindFlag(string_view Tag,unsigned long &Flags, unsigned long Flag) const { unsigned int Pos; @@ -986,7 +985,7 @@ pkgTagSection::Tag pkgTagSection::Tag::Rewrite(std::string const &Name, std::str else return Tag(REWRITE, Name, Data); } -static bool WriteTag(FileFd &File, std::string Tag, StringView Value, pkgTagSection::WriteFlags flags) +static bool WriteTag(FileFd &File, std::string Tag, string_view Value, pkgTagSection::WriteFlags flags) { if (Value.empty() || isspace_ascii(Value[0]) != 0) Tag.append(":"); diff --git a/apt-pkg/tagfile.h b/apt-pkg/tagfile.h index e9a8ff461..bea6f37ba 100644 --- a/apt-pkg/tagfile.h +++ b/apt-pkg/tagfile.h @@ -28,7 +28,6 @@ #include #include #include -#include class FileFd; @@ -51,8 +50,8 @@ class APT_PUBLIC pkgTagSection std::unique_ptr const d; APT_HIDDEN bool FindInternal(unsigned int Pos,const char *&Start, const char *&End) const; - APT_HIDDEN APT::StringView FindInternal(unsigned int Pos) const; - APT_HIDDEN APT::StringView FindRawInternal(unsigned int Pos) const; + APT_HIDDEN std::string_view FindInternal(unsigned int Pos) const; + APT_HIDDEN std::string_view FindRawInternal(unsigned int Pos) const; APT_HIDDEN signed int FindIInternal(unsigned int Pos,signed long Default = 0) const; APT_HIDDEN bool FindBInternal(unsigned int Pos, bool Default = false) const; APT_HIDDEN unsigned long long FindULLInternal(unsigned int Pos, unsigned long long const &Default = 0) const; @@ -68,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 std::string{Find(sv)}; } - std::string FindRawS(APT::StringView sv) const { return std::string{FindRaw(sv)}; }; + std::string FindS(std::string_view sv) const { return std::string{Find(sv)}; } + std::string FindRawS(std::string_view sv) const { return std::string{FindRaw(sv)}; }; // Functions for lookup with a perfect hash function enum class Key; @@ -82,23 +81,23 @@ class APT_PUBLIC pkgTagSection bool FindFlag(Key key,uint8_t &Flags, uint8_t const Flag) const; bool FindFlag(Key key,unsigned long &Flags, unsigned long Flag) const; bool Exists(Key key) const; - APT::StringView Find(Key key) const; - APT::StringView FindRaw(Key key) const; + std::string_view Find(Key key) const; + std::string_view FindRaw(Key key) const; #endif - bool Find(APT::StringView Tag,const char *&Start, const char *&End) const; - bool Find(APT::StringView Tag,unsigned int &Pos) const; - APT::StringView Find(APT::StringView Tag) const; - APT::StringView FindRaw(APT::StringView Tag) const; - signed int FindI(APT::StringView Tag,signed long Default = 0) const; - bool FindB(APT::StringView, bool Default = false) const; - unsigned long long FindULL(APT::StringView Tag, unsigned long long const &Default = 0) const; + bool Find(std::string_view Tag,const char *&Start, const char *&End) const; + bool Find(std::string_view Tag,unsigned int &Pos) const; + std::string_view Find(std::string_view Tag) const; + std::string_view FindRaw(std::string_view Tag) const; + signed int FindI(std::string_view Tag,signed long Default = 0) const; + bool FindB(std::string_view, bool Default = false) const; + unsigned long long FindULL(std::string_view Tag, unsigned long long const &Default = 0) const; - bool FindFlag(APT::StringView Tag,uint8_t &Flags, + bool FindFlag(std::string_view Tag,uint8_t &Flags, uint8_t const Flag) const; - bool FindFlag(APT::StringView Tag,unsigned long &Flags, + bool FindFlag(std::string_view Tag,unsigned long &Flags, unsigned long Flag) const; - bool Exists(APT::StringView Tag) const; + bool Exists(std::string_view Tag) const; bool static FindFlag(uint8_t &Flags, uint8_t const Flag, const char* const Start, const char* const Stop); -- cgit v1.2.3-70-g09d2