[poppler] goo/GooString.cc goo/GooString.h
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Mar 28 12:05:07 UTC 2022
goo/GooString.cc | 18 ++----------------
goo/GooString.h | 3 +++
2 files changed, 5 insertions(+), 16 deletions(-)
New commits:
commit 5bebbe59a1e971dfd6b2f1f76d51dc544239ffb6
Author: Albert Astals Cid <aacid at kde.org>
Date: Tue Feb 22 16:01:19 2022 +0100
GooString: Introduce string_view ends/startsWith functions
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 4f46b85d..470b79f5 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -617,26 +617,12 @@ void GooString::prependUnicodeMarker()
bool GooString::startsWith(const char *prefix) const
{
- const auto len = size();
- const auto prefixLen = std::strlen(prefix);
-
- if (len < prefixLen) {
- return false;
- }
-
- return static_cast<const std::string &>(*this).compare(0, prefixLen, prefix) == 0;
+ return startsWith(toStr(), prefix);
}
bool GooString::endsWith(const char *suffix) const
{
- const auto len = size();
- const auto suffixLen = std::strlen(suffix);
-
- if (len < suffixLen) {
- return false;
- }
-
- return static_cast<const std::string &>(*this).compare(len - suffixLen, suffixLen, suffix) == 0;
+ return endsWith(toStr(), suffix);
}
GooString *GooString::sanitizedName(bool psmode) const
diff --git a/goo/GooString.h b/goo/GooString.h
index f2d01108..d83fcb95 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -239,6 +239,9 @@ public:
// Return true if string ends with suffix
POPPLER_PRIVATE_EXPORT bool endsWith(const char *suffix) const;
+ static bool startsWith(std::string_view str, std::string_view prefix) { return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix); }
+ static bool endsWith(std::string_view str, std::string_view suffix) { return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix); }
+
bool hasUnicodeMarker() const { return hasUnicodeMarker(*this); }
static bool hasUnicodeMarker(const std::string &s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; }
bool hasUnicodeMarkerLE() const { return hasUnicodeMarkerLE(*this); }
More information about the poppler
mailing list