summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Sander <oliver.sander@tu-dresden.de>2024-04-04 10:06:56 +0200
committerAlbert Astals Cid <aacid@kde.org>2024-04-04 09:28:58 +0000
commitfbb64544e5ea25ac9b1bd25b48043d074efe9cd9 (patch)
treeb106316a96314758a6cf0907485f73878bb46b37
parent508affb41a197895ce6af32d2404b8c7b812a70f (diff)
Remove GooString::startsWith and GooString::endsWith
Starting with C++20, the std::string class has methods starts_with and ends_with, which do the same thing. Use those instead.
-rw-r--r--goo/GooString.cc10
-rw-r--r--goo/GooString.h8
-rw-r--r--poppler/Form.cc4
-rw-r--r--poppler/GfxFont.cc2
-rw-r--r--poppler/GlobalParams.cc6
5 files changed, 9 insertions, 21 deletions
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 2f8ba7ad..a4b5fb9f 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -625,13 +625,3 @@ void GooString::prependUnicodeMarker()
{
insert(0, "\xFE\xFF", 2);
}
-
-bool GooString::startsWith(const char *prefix) const
-{
- return startsWith(toStr(), prefix);
-}
-
-bool GooString::endsWith(const char *suffix) const
-{
- return endsWith(toStr(), suffix);
-}
diff --git a/goo/GooString.h b/goo/GooString.h
index 9bacc22f..7ad9a524 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -242,12 +242,10 @@ public:
int cmpN(const char *sA, int n) const { return compare(0, n, sA); }
// Return true if strings starts with prefix
- POPPLER_PRIVATE_EXPORT bool startsWith(const char *prefix) const;
- // Return true if string ends with suffix
- POPPLER_PRIVATE_EXPORT bool endsWith(const char *suffix) const;
+ using std::string::starts_with;
- 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); }
+ // Return true if string ends with suffix
+ using std::string::ends_with;
bool hasUnicodeMarker() const { return hasUnicodeMarker(*this); }
static bool hasUnicodeMarker(const std::string &s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; }
diff --git a/poppler/Form.cc b/poppler/Form.cc
index b20d7857..bb5cac7f 100644
--- a/poppler/Form.cc
+++ b/poppler/Form.cc
@@ -2768,7 +2768,7 @@ std::string Form::findFontInDefaultResources(const std::string &fontFamily, cons
const Dict *fontDict = fontDictObj.getDict();
for (int i = 0; i < fontDict->getLength(); ++i) {
const char *key = fontDict->getKey(i);
- if (GooString::startsWith(key, kOurDictFontNamePrefix)) {
+ if (std::string_view(key).starts_with(kOurDictFontNamePrefix)) {
const Object fontObj = fontDict->getVal(i);
if (fontObj.isDict() && fontObj.dictIs("Font")) {
const Object fontBaseFontObj = fontObj.dictLookup("BaseFont");
@@ -2799,7 +2799,7 @@ Form::AddFontResult Form::addFontToDefaultResources(const std::string &fontFamil
Form::AddFontResult Form::addFontToDefaultResources(const std::string &filepath, int faceIndex, const std::string &fontFamily, const std::string &fontStyle, bool forceName)
{
- if (!GooString::endsWith(filepath, ".ttf") && !GooString::endsWith(filepath, ".ttc") && !GooString::endsWith(filepath, ".otf")) {
+ if (!filepath.ends_with(".ttf") && !filepath.ends_with(".ttc") && !filepath.ends_with(".otf")) {
error(errIO, -1, "We only support embedding ttf/ttc/otf fonts for now. The font file for {0:s} {1:s} was {2:s}", fontFamily.c_str(), fontStyle.c_str(), filepath.c_str());
return {};
}
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 21e8693d..9652617c 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -1251,7 +1251,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, std::optional<st
// pass 1: use the name-to-Unicode mapping table
missing = hex = false;
- bool isZapfDingbats = name && GooString::endsWith(*name, "ZapfDingbats");
+ bool isZapfDingbats = name && name->ends_with("ZapfDingbats");
for (int code = 0; code < 256; ++code) {
if ((charName = enc[code])) {
if (isZapfDingbats) {
diff --git a/poppler/GlobalParams.cc b/poppler/GlobalParams.cc
index 7da1232a..874cdc93 100644
--- a/poppler/GlobalParams.cc
+++ b/poppler/GlobalParams.cc
@@ -903,7 +903,7 @@ GooString *GlobalParams::findFontFile(const std::string &fontName)
static bool supportedFontForEmbedding(Unicode uChar, const char *filepath, int faceIndex)
{
- if (!GooString::endsWith(filepath, ".ttf") && !GooString::endsWith(filepath, ".ttc") && !GooString::endsWith(filepath, ".otf")) {
+ if (!std::string_view(filepath).ends_with(".ttf") && !std::string_view(filepath).ends_with(".ttc") && !std::string_view(filepath).ends_with(".otf")) {
// for now we only support ttf, ttc, otf fonts
return false;
}
@@ -1248,9 +1248,9 @@ GooString *GlobalParams::findSystemFontFile(const GfxFont *font, SysFontType *ty
// Set the type of font. Fonts returned by AFontMatcher are of
// four possible types - ttf, otf, ttc, otc.
- if (path->endsWith(".ttf") || path->endsWith(".otf")) {
+ if (path->ends_with(".ttf") || path->ends_with(".otf")) {
*type = sysFontTTF;
- } else if (path->endsWith(".ttc") || path->endsWith(".otc")) {
+ } else if (path->ends_with(".ttc") || path->ends_with(".otc")) {
*type = sysFontTTC;
}
# else