diff options
| author | Julian Andres Klode <jak@debian.org> | 2021-02-09 09:38:48 +0000 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2021-02-09 09:38:48 +0000 |
| commit | cb60beb83610783f664da0bbe1cdb7211aaba90f (patch) | |
| tree | a594f98222c256e6cec1a97c87305083823f0c91 /apt-pkg/contrib/string_view.h | |
| parent | 4c3383746f2974be5fdec86616f45fd85948a9aa (diff) | |
| parent | 131d0e3a261076da715102cb79275988cac810d1 (diff) | |
Merge branch 'pu/fuzzerpatches' into 'master'
Various patches uplifted from unfinished fuzzer branches
See merge request apt-team/apt!158
Diffstat (limited to 'apt-pkg/contrib/string_view.h')
| -rw-r--r-- | apt-pkg/contrib/string_view.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h index 05aad3327..04f6ff115 100644 --- a/apt-pkg/contrib/string_view.h +++ b/apt-pkg/contrib/string_view.h @@ -39,6 +39,10 @@ public: StringView(const char *data) : data_(data), size_(strlen(data)) {} StringView(std::string const & str): data_(str.data()), size_(str.size()) {} + /* Modifiers */ + void remove_prefix(size_t n) { data_ += n; size_ -= n; } + void remove_suffix(size_t n) { size_ -= n; } + void clear() { size_ = 0; } /* Viewers */ constexpr StringView substr(size_t pos, size_t n = npos) const { @@ -76,6 +80,28 @@ public: return found - data_; } + size_t find(APT::StringView const needle) const { + if (needle.empty()) + return npos; + if (needle.length() == 1) + return find(*needle.data()); + size_t found = 0; + while ((found = find(*needle.data(), found)) != npos) { + if (compare(found, needle.length(), needle) == 0) + return found; + ++found; + } + return found; + } + size_t find(APT::StringView const needle, size_t pos) const { + if (pos == 0) + return find(needle); + size_t const found = substr(pos).find(needle); + if (found == npos) + return npos; + return pos + found; + } + /* Conversions */ std::string to_string() const { return std::string(data_, size_); |
