8 #ifndef SkString_DEFINED
9 #define SkString_DEFINED
14 #include "include/private/base/SkTo.h"
15 #include "include/private/base/SkTypeTraits.h"
22 #include <string_view>
23 #include <type_traits>
29 return !strncmp(
string, prefixStr, strlen(prefixStr));
33 return (prefixChar == *
string);
41 static inline int SkStrFind(
const char string[],
const char substring[]) {
42 const char *first = strstr(
string, substring);
43 if (
nullptr == first)
return -1;
44 return SkToInt(first - &
string[0]);
48 const char* last = strrchr(
string, subchar);
49 if (
nullptr == last)
return -1;
50 return SkToInt(last - &
string[0]);
53 static inline bool SkStrContains(
const char string[],
const char substring[]) {
56 return (-1 !=
SkStrFind(
string, substring));
58 static inline bool SkStrContains(
const char string[],
const char subchar) {
130 bool isEmpty()
const {
return 0 == fRec->fLength; }
131 size_t size()
const {
return (
size_t) fRec->fLength; }
132 const char*
data()
const {
return fRec->data(); }
133 const char*
c_str()
const {
return fRec->data(); }
138 bool equals(
const char text[],
size_t len)
const;
158 int find(
const char substring[])
const {
159 return SkStrFind(fRec->data(), substring);
187 void set(
const char text[]);
188 void set(
const char text[],
size_t len);
189 void set(std::string_view str) { this->
set(str.data(), str.size()); }
191 void insert(
size_t offset,
const char text[]);
192 void insert(
size_t offset,
const char text[],
size_t len);
194 void insert(
size_t offset, std::string_view str) { this->
insert(offset, str.data(), str.size()); }
197 void insertS64(
size_t offset, int64_t value,
int minDigits = 0);
199 void insertU64(
size_t offset, uint64_t value,
int minDigits = 0);
200 void insertHex(
size_t offset, uint32_t value,
int minDigits = 0);
203 void append(
const char text[]) { this->insert((
size_t)-1, text); }
204 void append(
const char text[],
size_t len) { this->insert((
size_t)-1, text, len); }
206 void append(std::string_view str) { this->insert((
size_t)-1, str.data(), str.size()); }
208 void appendS32(int32_t value) { this->insertS32((
size_t)-1, value); }
209 void appendS64(int64_t value,
int minDigits = 0) { this->insertS64((
size_t)-1, value, minDigits); }
210 void appendU32(uint32_t value) { this->insertU32((
size_t)-1, value); }
211 void appendU64(uint64_t value,
int minDigits = 0) { this->insertU64((
size_t)-1, value, minDigits); }
212 void appendHex(uint32_t value,
int minDigits = 0) { this->insertHex((
size_t)-1, value, minDigits); }
215 void prepend(
const char text[]) { this->insert(0, text); }
216 void prepend(
const char text[],
size_t len) { this->insert(0, text, len); }
218 void prepend(std::string_view str) { this->insert(0, str.data(), str.size()); }
220 void prependS32(int32_t value) { this->insertS32(0, value); }
221 void prependS64(int32_t value,
int minDigits = 0) { this->insertS64(0, value, minDigits); }
222 void prependHex(uint32_t value,
int minDigits = 0) { this->insertHex(0, value, minDigits); }
225 void printf(
const char format[], ...) SK_PRINTF_LIKE(2, 3);
226 void printVAList(const
char format[], va_list) SK_PRINTF_LIKE(2, 0);
227 void appendf(const
char format[], ...) SK_PRINTF_LIKE(2, 3);
228 void appendVAList(const
char format[], va_list) SK_PRINTF_LIKE(2, 0);
229 void prependf(const
char format[], ...) SK_PRINTF_LIKE(2, 3);
230 void prependVAList(const
char format[], va_list) SK_PRINTF_LIKE(2, 0);
232 void remove(
size_t offset,
size_t length);
249 constexpr Rec(uint32_t len, int32_t refCnt) : fLength(len), fRefCnt(refCnt) {}
251 char* data() {
return fBeginningOfData; }
252 const char* data()
const {
return fBeginningOfData; }
257 int32_t getRefCnt()
const;
262 mutable std::atomic<int32_t> fRefCnt;
263 char fBeginningOfData[1] = {
'\0'};
266 void operator delete(
void* p) { ::operator
delete(p); }
270 static_assert(::sk_is_trivially_relocatable<decltype(fRec)>::value);
276 SkString& validate() {
return *
this; }
277 const SkString& validate()
const {
return *
this; }
280 static const Rec gEmptyRec;
float SkScalar
Definition: SkScalar.h:14
SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static constexpr int kSkStrAppendS32_MaxSize
Definition: SkString.h:89
static constexpr int kSkStrAppendS64_MaxSize
Definition: SkString.h:91
static constexpr int kSkStrAppendU32_MaxSize
Definition: SkString.h:84
static void swap(SkString &a, SkString &b)
Definition: SkString.h:289
static int SkStrFindLastOf(const char string[], const char subchar)
Definition: SkString.h:47
char * SkStrAppendU64(char buffer[], uint64_t, int minDigits)
static constexpr int kSkStrAppendScalar_MaxSize
Floats have at most 8 significant digits, so we limit our g to that.
Definition: SkString.h:101
bool SkStrEndsWith(const char string[], const char suffixStr[])
static bool SkStrStartsWith(const char string[], const char prefixStr[])
Definition: SkString.h:26
char * SkStrAppendS64(char buffer[], int64_t, int minDigits)
static int SkStrFind(const char string[], const char substring[])
Definition: SkString.h:41
static constexpr int kSkStrAppendU64_MaxSize
Definition: SkString.h:86
char * SkStrAppendScalar(char buffer[], SkScalar)
Write the scalar in decimal format into buffer, and return a pointer to the next char after the last ...
char * SkStrAppendS32(char buffer[], int32_t)
static bool SkStrContains(const char string[], const char substring[])
Definition: SkString.h:53
char * SkStrAppendU32(char buffer[], uint32_t)
int SkStrStartsWithOneOf(const char string[], const char prefixes[])
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:167
Light weight class for managing strings.
Definition: SkString.h:118
void insertScalar(size_t offset, SkScalar)
void appendUnichar(SkUnichar uni)
Definition: SkString.h:207
void insertUnichar(size_t offset, SkUnichar)
void set(const char text[], size_t len)
void append(const char text[], size_t len)
Definition: SkString.h:204
bool endsWith(const char suffixChar) const
Definition: SkString.h:149
SkString & operator=(SkString &&)
bool startsWith(const char prefixStr[]) const
Definition: SkString.h:140
friend bool operator==(const SkString &a, const SkString &b)
Definition: SkString.h:165
bool equals(const char text[]) const
bool startsWith(const char prefixChar) const
Definition: SkString.h:143
void prependS64(int32_t value, int minDigits=0)
Definition: SkString.h:221
const char * data() const
Definition: SkString.h:132
void append(const SkString &str)
Definition: SkString.h:205
void printf(const char format[],...) SK_PRINTF_LIKE(2
void prepend(const char text[], size_t len)
Definition: SkString.h:216
SkString(const SkString &)
void insertU64(size_t offset, uint64_t value, int minDigits=0)
void prependS32(int32_t value)
Definition: SkString.h:220
bool equals(const char text[], size_t len) const
void appendS64(int64_t value, int minDigits=0)
Definition: SkString.h:209
void insert(size_t offset, const SkString &str)
Definition: SkString.h:193
SkString(const std::string &)
size_t size() const
Definition: SkString.h:131
void prependScalar(SkScalar value)
Definition: SkString.h:223
void insertU32(size_t offset, uint32_t value)
SkString & operator+=(const char c)
Definition: SkString.h:236
void appendU64(uint64_t value, int minDigits=0)
Definition: SkString.h:211
void insertS32(size_t offset, int32_t value)
void set(const SkString &src)
Definition: SkString.h:186
bool equals(const SkString &) const
void prependUnichar(SkUnichar uni)
Definition: SkString.h:219
bool isEmpty() const
Definition: SkString.h:130
int find(const char substring[]) const
Definition: SkString.h:158
void append(const char text[])
Definition: SkString.h:203
void swap(SkString &other)
Swap contents between this and other.
void prepend(const SkString &str)
Definition: SkString.h:217
void set(std::string_view str)
Definition: SkString.h:189
void appendHex(uint32_t value, int minDigits=0)
Definition: SkString.h:212
void appendS32(int32_t value)
Definition: SkString.h:208
bool contains(const char substring[]) const
Definition: SkString.h:152
SkString(const char text[], size_t len)
void append(std::string_view str)
Definition: SkString.h:206
void resize(size_t len)
String contents are preserved on resize.
void appendScalar(SkScalar value)
Definition: SkString.h:213
char & operator[](size_t n)
Definition: SkString.h:179
void insert(size_t offset, const char text[])
void appendU32(uint32_t value)
Definition: SkString.h:210
SkString & operator=(const char text[])
void insert(size_t offset, const char text[], size_t len)
SkString & operator+=(const char text[])
Definition: SkString.h:235
bool endsWith(const char suffixStr[]) const
Definition: SkString.h:146
void prepend(std::string_view str)
Definition: SkString.h:218
bool contains(const char subchar) const
Definition: SkString.h:155
void prependHex(uint32_t value, int minDigits=0)
Definition: SkString.h:222
std::true_type sk_is_trivially_relocatable
Definition: SkString.h:244
SkString & operator=(const SkString &)
char operator[](size_t n) const
Definition: SkString.h:134
void set(const char text[])
friend bool operator!=(const SkString &a, const SkString &b)
Definition: SkString.h:168
SkString(std::string_view)
SkString(const char text[])
void prepend(const char text[])
Definition: SkString.h:215
void insert(size_t offset, std::string_view str)
Definition: SkString.h:194
const char * c_str() const
Definition: SkString.h:133
void insertS64(size_t offset, int64_t value, int minDigits=0)
int findLastOf(const char subchar) const
Definition: SkString.h:161
void insertHex(size_t offset, uint32_t value, int minDigits=0)
sk_sp< SkDrawLooper > SK_API Make(SkColor4f color, SkColorSpace *cs, SkScalar sigma, SkScalar dx, SkScalar dy)