summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-01-15 15:57:32 +0100
committerDavid Kalnischkies <david@kalnischkies.de>2016-01-15 18:19:16 +0100
commit9b2845e1691b5587d731c3dae9f695ca2db0be1a (patch)
tree57cdbc9c5176b41252dd23413d466b7b2f98a43d /apt-pkg/contrib
parentc987dff466fcb80278851df212f86cfce86ee9bc (diff)
return correct position in APT::StringView::(r)find
The position returned is supposed to be the position of the character counted from the start of the string, but if we used the substr calling overloads the skipped over prefix wasn't considered. The pos parameter of rfind had also the wrong semantic.
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/string_view.h24
1 files changed, 16 insertions, 8 deletions
diff --git a/apt-pkg/contrib/string_view.h b/apt-pkg/contrib/string_view.h
index 5b6411a33..d4ff80028 100644
--- a/apt-pkg/contrib/string_view.h
+++ b/apt-pkg/contrib/string_view.h
@@ -29,6 +29,7 @@ class StringView {
public:
static constexpr size_t npos = static_cast<size_t>(-1);
+ static_assert(APT::StringView::npos == std::string::npos, "npos values are different");
/* Constructors */
constexpr StringView() : data_(""), size_(0) {}
@@ -43,10 +44,15 @@ public:
return StringView(data_ + pos, n > (size_ - pos) ? (size_ - pos) : n);
}
- size_t find(int c, size_t pos=0) const {
- if (pos != 0)
- return substr(pos).find(c);
-
+ size_t find(int c, size_t pos) const {
+ if (pos == 0)
+ return find(c);
+ size_t const found = substr(pos).find(c);
+ if (found == npos)
+ return npos;
+ return pos + found;
+ }
+ size_t find(int c) const {
const char *found = static_cast<const char*>(memchr(data_, c, size_));
if (found == NULL)
@@ -55,10 +61,12 @@ public:
return found - data_;
}
- size_t rfind(int c, size_t pos=npos) const {
- if (pos != npos)
- return substr(0, pos).rfind(c);
-
+ size_t rfind(int c, size_t pos) const {
+ if (pos == npos)
+ return rfind(c);
+ return APT::StringView(data_, pos).rfind(c);
+ }
+ size_t rfind(int c) const {
const char *found = static_cast<const char*>(memrchr(data_, c, size_));
if (found == NULL)