From fbb64544e5ea25ac9b1bd25b48043d074efe9cd9 Mon Sep 17 00:00:00 2001 From: Oliver Sander Date: Thu, 4 Apr 2024 10:06:56 +0200 Subject: 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. --- goo/GooString.cc | 10 ---------- goo/GooString.h | 8 +++----- poppler/Form.cc | 4 ++-- poppler/GfxFont.cc | 2 +- poppler/GlobalParams.cc | 6 +++--- 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::optionalends_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 -- cgit v1.2.3