diff options
author | David Kalnischkies <david@kalnischkies.de> | 2019-01-29 15:34:56 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2019-01-29 16:08:39 +0100 |
commit | cd852177246a5ea52ae3fda12b8d991a1ad8d351 (patch) | |
tree | 9ae05cf2fda1f8c0abeb3f884a33e4ebff1b0fca /apt-pkg/contrib/gpgv.cc | |
parent | 7107b3a056211daf7cd00b130f42168d6aa1e1b6 (diff) | |
download | apt-cd852177246a5ea52ae3fda12b8d991a1ad8d351.tar.gz |
Reuse APT::StringView more in LineBuffer
No effective change in behaviour, just simplifying and reusing code.
Suggested-By: Julian Andres Klode
Gbp-Dch: Ignore
Diffstat (limited to 'apt-pkg/contrib/gpgv.cc')
-rw-r--r-- | apt-pkg/contrib/gpgv.cc | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 88cf0afc9..73fddf38c 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -46,40 +46,17 @@ class LineBuffer /*{{{*/ // a "normal" find_last_not_of returns npos if not found int find_last_not_of_length(APT::StringView const bad) const { - if (empty()) - return 0; - int result = line_length - 1; - while (result >= 0) - { - if (std::find(bad.begin(), bad.end(), buffer[result]) == bad.end()) - break; - --result; - } - return result + 1; + for (int result = line_length - 1; result >= 0; --result) + if (bad.find(buffer[result]) == APT::StringView::npos) + return result + 1; + return 0; } public: - bool empty() const noexcept - { - return line_length <= 0; - } - APT::StringView view() const noexcept - { - return {buffer, static_cast<size_t>(line_length)}; - } - std::string str() const noexcept - { - if (empty()) - return {}; - return {buffer, static_cast<std::string::size_type>(line_length)}; - } - bool starts_with(APT::StringView const start) const - { - auto const line = view(); - if (line.length() < start.length()) - return false; - return line.compare(0, start.length(), start) == 0; - } + bool empty() const noexcept { return view().empty(); } + APT::StringView view() const noexcept { return {buffer, static_cast<size_t>(line_length)}; } + bool starts_with(APT::StringView const start) const { return view().substr(0, start.size()) == start; } + bool writeTo(FileFd *const to, bool const prefixNL = false, bool const postfixNL = true, size_t offset = 0) const { if (to == nullptr) @@ -471,7 +448,7 @@ bool SplitClearSignedFile(std::string const &InFile, FileFd * const ContentFile, // but we assume that there will never be a header key starting with a dash return _error->Error("Clearsigned file '%s' contains unexpected line starting with a dash (%s)", InFile.c_str(), "armor"); if (ContentHeader != nullptr && buf.starts_with("Hash: ")) - ContentHeader->push_back(buf.str()); + ContentHeader->push_back(buf.view().to_string()); } // the message itself |