|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GooString_H |
|
#define GooString_H |
|
|
|
#include "poppler_private_export.h" |
|
|
|
#include <cstdarg> |
|
#include <memory> |
|
#include <string> |
|
|
|
#ifdef __clang__ |
|
# define GOOSTRING_FORMAT __attribute__((__annotate__("gooformat"))) |
|
#else |
|
# define GOOSTRING_FORMAT |
|
#endif |
|
|
|
class GooString : private std::string |
|
{ |
|
public: |
|
|
|
GooString() = default; |
|
|
|
|
|
~GooString() = default; |
|
|
|
GooString(GooString &&other) = default; |
|
GooString &operator=(GooString &&other) = default; |
|
|
|
GooString(const GooString &other) = delete; |
|
GooString &operator=(const GooString &other) = delete; |
|
|
|
|
|
explicit GooString(const char *sA) : std::string(sA ? sA : "") { } |
|
|
|
|
|
explicit GooString(const std::string &str) : std::string(str) { } |
|
explicit GooString(std::string &&str) : std::string(std::move(str)) { } |
|
|
|
const std::string &toStr() const { return *this; } |
|
std::string &toNonConstStr() { return *this; } |
|
|
|
|
|
|
|
GooString(const char *sA, size_t lengthA) : std::string(sA ? sA : "", sA ? lengthA : 0) { } |
|
|
|
|
|
GooString(const GooString *str, int idx, size_t lengthA) : std::string(*str, idx, lengthA) { } |
|
GooString(const std::string &str, int idx, size_t lengthA) : std::string(str, idx, lengthA) { } |
|
|
|
|
|
GooString *Set(const GooString *newStr) |
|
{ |
|
assign(newStr ? static_cast<const std::string &>(*newStr) : std::string {}); |
|
return this; |
|
} |
|
GooString *Set(const char *newStr) |
|
{ |
|
assign(newStr ? newStr : ""); |
|
return this; |
|
} |
|
GooString *Set(const char *newStr, int newLen) |
|
{ |
|
assign(newStr ? newStr : "", newStr ? newLen : 0); |
|
return this; |
|
} |
|
|
|
|
|
explicit GooString(const GooString *str) : std::string(str ? static_cast<const std::string &>(*str) : std::string {}) { } |
|
GooString *copy() const { return new GooString(this); } |
|
|
|
|
|
GooString(const GooString *str1, const GooString *str2) |
|
{ |
|
reserve(str1->size() + str2->size()); |
|
static_cast<std::string &>(*this).append(*str1); |
|
static_cast<std::string &>(*this).append(*str2); |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> format(const char *fmt, ...) GOOSTRING_FORMAT; |
|
POPPLER_PRIVATE_EXPORT static std::unique_ptr<GooString> formatv(const char *fmt, va_list argList); |
|
|
|
|
|
int getLength() const { return size(); } |
|
|
|
|
|
using std::string::c_str; |
|
|
|
|
|
char getChar(size_t i) const { return (*this)[i]; } |
|
|
|
|
|
void setChar(int i, char c) { (*this)[i] = c; } |
|
|
|
|
|
GooString *clear() |
|
{ |
|
static_cast<std::string &>(*this).clear(); |
|
return this; |
|
} |
|
|
|
|
|
GooString *append(char c) |
|
{ |
|
push_back(c); |
|
return this; |
|
} |
|
GooString *append(const GooString *str) |
|
{ |
|
static_cast<std::string &>(*this).append(*str); |
|
return this; |
|
} |
|
GooString *append(const std::string &str) |
|
{ |
|
static_cast<std::string &>(*this).append(str); |
|
return this; |
|
} |
|
GooString *append(const char *str) |
|
{ |
|
static_cast<std::string &>(*this).append(str); |
|
return this; |
|
} |
|
GooString *append(const char *str, size_t lengthA) |
|
{ |
|
static_cast<std::string &>(*this).append(str, lengthA); |
|
return this; |
|
} |
|
|
|
|
|
POPPLER_PRIVATE_EXPORT GooString *appendf(const char *fmt, ...) GOOSTRING_FORMAT; |
|
POPPLER_PRIVATE_EXPORT GooString *appendfv(const char *fmt, va_list argList); |
|
|
|
|
|
GooString *insert(int i, char c) |
|
{ |
|
static_cast<std::string &>(*this).insert(i, 1, c); |
|
return this; |
|
} |
|
GooString *insert(int i, const GooString *str) |
|
{ |
|
static_cast<std::string &>(*this).insert(i, *str); |
|
return this; |
|
} |
|
GooString *insert(int i, const std::string &str) |
|
{ |
|
static_cast<std::string &>(*this).insert(i, str); |
|
return this; |
|
} |
|
GooString *insert(int i, const char *str) |
|
{ |
|
static_cast<std::string &>(*this).insert(i, str); |
|
return this; |
|
} |
|
GooString *insert(int i, const char *str, int lengthA) |
|
{ |
|
static_cast<std::string &>(*this).insert(i, str, lengthA); |
|
return this; |
|
} |
|
|
|
|
|
GooString *del(int i, int n = 1) |
|
{ |
|
erase(i, n); |
|
return this; |
|
} |
|
|
|
|
|
POPPLER_PRIVATE_EXPORT GooString *lowerCase(); |
|
POPPLER_PRIVATE_EXPORT static void lowerCase(std::string &s); |
|
|
|
|
|
POPPLER_PRIVATE_EXPORT static std::string toLowerCase(const std::string &s); |
|
|
|
|
|
int cmp(const GooString *str) const { return compare(*str); } |
|
int cmp(const std::string &str) const { return compare(str); } |
|
int cmpN(GooString *str, int n) const { return compare(0, n, *str); } |
|
int cmp(const char *sA) const { return compare(sA); } |
|
int cmpN(const char *sA, int n) const { return compare(0, n, sA); } |
|
|
|
|
|
POPPLER_PRIVATE_EXPORT bool startsWith(const char *prefix) const; |
|
|
|
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); } |
|
static bool hasUnicodeMarkerLE(const std::string &s) { return s.size() >= 2 && s[0] == '\xff' && s[1] == '\xfe'; } |
|
|
|
POPPLER_PRIVATE_EXPORT void prependUnicodeMarker(); |
|
}; |
|
|
|
#endif |
|
|