File indexing completed on 2025-12-11 10:26:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 #ifndef GooString_H
0040 #define GooString_H
0041
0042 #include "poppler_private_export.h"
0043
0044 #include <cstdarg>
0045 #include <memory>
0046 #include <string>
0047
0048 #ifdef __clang__
0049 # define GOOSTRING_FORMAT __attribute__((__annotate__("gooformat")))
0050 #else
0051 # define GOOSTRING_FORMAT
0052 #endif
0053
0054 class GooString : private std::string
0055 {
0056 public:
0057
0058 GooString() = default;
0059
0060
0061 ~GooString() = default;
0062
0063 GooString(GooString &&other) = default;
0064 GooString &operator=(GooString &&other) = default;
0065
0066 GooString(const GooString &other) = delete;
0067 GooString &operator=(const GooString &other) = delete;
0068
0069
0070 explicit GooString(const char *sA) : std::string(sA ? sA : "") { }
0071
0072
0073 explicit GooString(const std::string &str) : std::string(str) { }
0074 explicit GooString(std::string &&str) : std::string(std::move(str)) { }
0075
0076 const std::string &toStr() const { return *this; }
0077 std::string &toNonConstStr() { return *this; }
0078
0079
0080
0081 GooString(const char *sA, size_t lengthA) : std::string(sA ? sA : "", sA ? lengthA : 0) { }
0082
0083
0084 GooString(const GooString *str, int idx, size_t lengthA) : std::string(*str, idx, lengthA) { }
0085 GooString(const std::string &str, int idx, size_t lengthA) : std::string(str, idx, lengthA) { }
0086
0087
0088 GooString *Set(const GooString *newStr)
0089 {
0090 assign(newStr ? static_cast<const std::string &>(*newStr) : std::string {});
0091 return this;
0092 }
0093 GooString *Set(const char *newStr)
0094 {
0095 assign(newStr ? newStr : "");
0096 return this;
0097 }
0098 GooString *Set(const char *newStr, int newLen)
0099 {
0100 assign(newStr ? newStr : "", newStr ? newLen : 0);
0101 return this;
0102 }
0103
0104
0105 explicit GooString(const GooString *str) : std::string(str ? static_cast<const std::string &>(*str) : std::string {}) { }
0106 GooString *copy() const { return new GooString(this); }
0107
0108
0109 GooString(const GooString *str1, const GooString *str2)
0110 {
0111 reserve(str1->size() + str2->size());
0112 static_cast<std::string &>(*this).append(*str1);
0113 static_cast<std::string &>(*this).append(*str2);
0114 }
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> format(const char *fmt, ...) GOOSTRING_FORMAT;
0144 POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> formatv(const char *fmt, va_list argList);
0145
0146
0147 int getLength() const { return size(); }
0148
0149
0150 using std::string::c_str;
0151
0152
0153 char getChar(size_t i) const { return (*this)[i]; }
0154
0155
0156 void setChar(int i, char c) { (*this)[i] = c; }
0157
0158
0159 GooString *clear()
0160 {
0161 static_cast<std::string &>(*this).clear();
0162 return this;
0163 }
0164
0165
0166 GooString *append(char c)
0167 {
0168 push_back(c);
0169 return this;
0170 }
0171 GooString *append(const GooString *str)
0172 {
0173 static_cast<std::string &>(*this).append(*str);
0174 return this;
0175 }
0176 GooString *append(const std::string &str)
0177 {
0178 static_cast<std::string &>(*this).append(str);
0179 return this;
0180 }
0181 GooString *append(const char *str)
0182 {
0183 static_cast<std::string &>(*this).append(str);
0184 return this;
0185 }
0186 GooString *append(const char *str, size_t lengthA)
0187 {
0188 static_cast<std::string &>(*this).append(str, lengthA);
0189 return this;
0190 }
0191
0192
0193 POPPLER_PRIVATE_EXPORT GooString *appendf(const char *fmt, ...) GOOSTRING_FORMAT;
0194 POPPLER_PRIVATE_EXPORT GooString *appendfv(const char *fmt, va_list argList);
0195
0196
0197 GooString *insert(int i, char c)
0198 {
0199 static_cast<std::string &>(*this).insert(i, 1, c);
0200 return this;
0201 }
0202 GooString *insert(int i, const GooString *str)
0203 {
0204 static_cast<std::string &>(*this).insert(i, *str);
0205 return this;
0206 }
0207 GooString *insert(int i, const std::string &str)
0208 {
0209 static_cast<std::string &>(*this).insert(i, str);
0210 return this;
0211 }
0212 GooString *insert(int i, const char *str)
0213 {
0214 static_cast<std::string &>(*this).insert(i, str);
0215 return this;
0216 }
0217 GooString *insert(int i, const char *str, int lengthA)
0218 {
0219 static_cast<std::string &>(*this).insert(i, str, lengthA);
0220 return this;
0221 }
0222
0223
0224 GooString *del(int i, int n = 1)
0225 {
0226 erase(i, n);
0227 return this;
0228 }
0229
0230
0231 POPPLER_PRIVATE_EXPORT GooString *lowerCase();
0232 POPPLER_PRIVATE_EXPORT static void lowerCase(std::string &s);
0233
0234
0235 POPPLER_PRIVATE_EXPORT static std::string toLowerCase(const std::string &s);
0236
0237
0238 int cmp(const GooString *str) const { return compare(*str); }
0239 int cmp(const std::string &str) const { return compare(str); }
0240 int cmpN(GooString *str, int n) const { return compare(0, n, *str); }
0241 int cmp(const char *sA) const { return compare(sA); }
0242 int cmpN(const char *sA, int n) const { return compare(0, n, sA); }
0243
0244
0245 POPPLER_PRIVATE_EXPORT bool startsWith(const char *prefix) const;
0246
0247 POPPLER_PRIVATE_EXPORT bool endsWith(const char *suffix) const;
0248
0249 static bool startsWith(std::string_view str, std::string_view prefix) { return str.size() >= prefix.size() && 0 == str.compare(0, prefix.size(), prefix); }
0250 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); }
0251
0252 bool hasUnicodeMarker() const { return hasUnicodeMarker(*this); }
0253 static bool hasUnicodeMarker(const std::string &s) { return s.size() >= 2 && s[0] == '\xfe' && s[1] == '\xff'; }
0254 bool hasUnicodeMarkerLE() const { return hasUnicodeMarkerLE(*this); }
0255 static bool hasUnicodeMarkerLE(const std::string &s) { return s.size() >= 2 && s[0] == '\xff' && s[1] == '\xfe'; }
0256 bool hasJustUnicodeMarker() const { return size() == 2 && hasUnicodeMarker(); }
0257
0258 POPPLER_PRIVATE_EXPORT void prependUnicodeMarker();
0259
0260
0261
0262
0263 POPPLER_PRIVATE_EXPORT GooString *sanitizedName() const;
0264 };
0265
0266 #endif