diff options
| author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2024-11-14 17:16:50 +0100 |
|---|---|---|
| committer | наб <nabijaczleweli@nabijaczleweli.xyz> | 2024-11-14 18:24:31 +0100 |
| commit | c2c98b6e251d221faea879058aa0e92436048e76 (patch) | |
| tree | 0ef5e83ef309c9645c104bb4277b16e8883e9b6f | |
| parent | de6ec4aca77d0a56e30d08dbc12661bdda0c6e69 (diff) | |
pkgTagSection::Tag constructors: std::string const& -> std::string_view (always copied) [#if APT_PKG_ABI > 600]
| -rw-r--r-- | apt-pkg/tagfile.cc | 28 | ||||
| -rw-r--r-- | apt-pkg/tagfile.h | 18 | ||||
| -rw-r--r-- | ftparchive/writer.cc | 4 |
3 files changed, 36 insertions, 14 deletions
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 cd1806eb4..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 @@ -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 |
