Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | Friends | List of all members
SkString Class Reference

#include <SkString.h>

Inheritance diagram for SkString:
DM::ImplicitString Gold

Public Types

using sk_is_trivially_relocatable = std::true_type
 

Public Member Functions

 SkString ()
 
 SkString (size_t len)
 
 SkString (const char text[])
 
 SkString (const char text[], size_t len)
 
 SkString (const SkString &)
 
 SkString (SkString &&)
 
 SkString (const std::string &)
 
 SkString (std::string_view)
 
 ~SkString ()
 
bool isEmpty () const
 
size_t size () const
 
const char * data () const
 
const char * c_str () const
 
char operator[] (size_t n) const
 
bool equals (const SkString &) const
 
bool equals (const char text[]) const
 
bool equals (const char text[], size_t len) const
 
bool startsWith (const char prefixStr[]) const
 
bool startsWith (const char prefixChar) const
 
bool endsWith (const char suffixStr[]) const
 
bool endsWith (const char suffixChar) const
 
bool contains (const char substring[]) const
 
bool contains (const char subchar) const
 
int find (const char substring[]) const
 
int findLastOf (const char subchar) const
 
SkStringoperator= (const SkString &)
 
SkStringoperator= (SkString &&)
 
SkStringoperator= (const char text[])
 
char * data ()
 
char & operator[] (size_t n)
 
void reset ()
 
void resize (size_t len)
 
void set (const SkString &src)
 
void set (const char text[])
 
void set (const char text[], size_t len)
 
void set (std::string_view str)
 
void insert (size_t offset, const char text[])
 
void insert (size_t offset, const char text[], size_t len)
 
void insert (size_t offset, const SkString &str)
 
void insert (size_t offset, std::string_view str)
 
void insertUnichar (size_t offset, SkUnichar)
 
void insertS32 (size_t offset, int32_t value)
 
void insertS64 (size_t offset, int64_t value, int minDigits=0)
 
void insertU32 (size_t offset, uint32_t value)
 
void insertU64 (size_t offset, uint64_t value, int minDigits=0)
 
void insertHex (size_t offset, uint32_t value, int minDigits=0)
 
void insertScalar (size_t offset, SkScalar)
 
void append (const char text[])
 
void append (const char text[], size_t len)
 
void append (const SkString &str)
 
void append (std::string_view str)
 
void appendUnichar (SkUnichar uni)
 
void appendS32 (int32_t value)
 
void appendS64 (int64_t value, int minDigits=0)
 
void appendU32 (uint32_t value)
 
void appendU64 (uint64_t value, int minDigits=0)
 
void appendHex (uint32_t value, int minDigits=0)
 
void appendScalar (SkScalar value)
 
void prepend (const char text[])
 
void prepend (const char text[], size_t len)
 
void prepend (const SkString &str)
 
void prepend (std::string_view str)
 
void prependUnichar (SkUnichar uni)
 
void prependS32 (int32_t value)
 
void prependS64 (int32_t value, int minDigits=0)
 
void prependHex (uint32_t value, int minDigits=0)
 
void prependScalar (SkScalar value)
 
void printf (const char format[],...) SK_PRINTF_LIKE(2
 
void void printVAList (const char format[], va_list) SK_PRINTF_LIKE(2
 
void void void appendf (const char format[],...) SK_PRINTF_LIKE(2
 
void void void void appendVAList (const char format[], va_list) SK_PRINTF_LIKE(2
 
void void void void void prependf (const char format[],...) SK_PRINTF_LIKE(2
 
void void void void void void prependVAList (const char format[], va_list) SK_PRINTF_LIKE(2
 
void void void void void void void remove (size_t offset, size_t length)
 
SkStringoperator+= (const SkString &s)
 
SkStringoperator+= (const char text[])
 
SkStringoperator+= (const char c)
 
void swap (SkString &other)
 

Friends

bool operator== (const SkString &a, const SkString &b)
 
bool operator!= (const SkString &a, const SkString &b)
 

Detailed Description

Light weight class for managing strings. Uses reference counting to make string assignments and copies very fast with no extra RAM cost. Assumes UTF8 encoding.

Definition at line 118 of file SkString.h.

Member Typedef Documentation

◆ sk_is_trivially_relocatable

using SkString::sk_is_trivially_relocatable = std::true_type

Definition at line 244 of file SkString.h.

Constructor & Destructor Documentation

◆ SkString() [1/8]

SkString::SkString ( )

Definition at line 289 of file SkString.cpp.

289 : fRec(const_cast<Rec*>(&gEmptyRec)) {
290}

◆ SkString() [2/8]

SkString::SkString ( size_t  len)
explicit

Definition at line 292 of file SkString.cpp.

292 {
293 fRec = Rec::Make(nullptr, len);
294}
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)

◆ SkString() [3/8]

SkString::SkString ( const char  text[])
explicit

Definition at line 296 of file SkString.cpp.

296 {
297 size_t len = text ? strlen(text) : 0;
298
299 fRec = Rec::Make(text, len);
300}
std::u16string text

◆ SkString() [4/8]

SkString::SkString ( const char  text[],
size_t  len 
)

Definition at line 302 of file SkString.cpp.

302 {
303 fRec = Rec::Make(text, len);
304}

◆ SkString() [5/8]

SkString::SkString ( const SkString src)

Definition at line 306 of file SkString.cpp.

306: fRec(src.validate().fRec) {}

◆ SkString() [6/8]

SkString::SkString ( SkString &&  src)

Definition at line 308 of file SkString.cpp.

308 : fRec(std::move(src.validate().fRec)) {
309 src.fRec.reset(const_cast<Rec*>(&gEmptyRec));
310}

◆ SkString() [7/8]

SkString::SkString ( const std::string &  src)
explicit

Definition at line 312 of file SkString.cpp.

312 {
313 fRec = Rec::Make(src.c_str(), src.size());
314}

◆ SkString() [8/8]

SkString::SkString ( std::string_view  src)
explicit

Definition at line 316 of file SkString.cpp.

316 {
317 fRec = Rec::Make(src.data(), src.length());
318}

◆ ~SkString()

SkString::~SkString ( )

Definition at line 320 of file SkString.cpp.

320 {
321 this->validate();
322}

Member Function Documentation

◆ append() [1/4]

void SkString::append ( const char  text[])
inline

Definition at line 203 of file SkString.h.

203{ this->insert((size_t)-1, text); }
void insert(size_t offset, const char text[])
Definition: SkString.cpp:415

◆ append() [2/4]

void SkString::append ( const char  text[],
size_t  len 
)
inline

Definition at line 204 of file SkString.h.

204{ this->insert((size_t)-1, text, len); }

◆ append() [3/4]

void SkString::append ( const SkString str)
inline

Definition at line 205 of file SkString.h.

205{ this->insert((size_t)-1, str.c_str(), str.size()); }
size_t size() const
Definition: SkString.h:131
const char * c_str() const
Definition: SkString.h:133

◆ append() [4/4]

void SkString::append ( std::string_view  str)
inline

Definition at line 206 of file SkString.h.

206{ this->insert((size_t)-1, str.data(), str.size()); }

◆ appendf()

void SkString::appendf ( const char  format[],
  ... 
)

Definition at line 550 of file SkString.cpp.

550 {
551 va_list args;
553 this->appendVAList(format, args);
554 va_end(args);
555}
void void void void appendVAList(const char format[], va_list) SK_PRINTF_LIKE(2
Definition: SkString.cpp:557
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
va_start(args, format)
va_end(args)

◆ appendHex()

void SkString::appendHex ( uint32_t  value,
int  minDigits = 0 
)
inline

Definition at line 212 of file SkString.h.

212{ this->insertHex((size_t)-1, value, minDigits); }
void insertHex(size_t offset, uint32_t value, int minDigits=0)
Definition: SkString.cpp:506
uint8_t value

◆ appendS32()

void SkString::appendS32 ( int32_t  value)
inline

Definition at line 208 of file SkString.h.

208{ this->insertS32((size_t)-1, value); }
void insertS32(size_t offset, int32_t value)
Definition: SkString.cpp:482

◆ appendS64()

void SkString::appendS64 ( int64_t  value,
int  minDigits = 0 
)
inline

Definition at line 209 of file SkString.h.

209{ this->insertS64((size_t)-1, value, minDigits); }
void insertS64(size_t offset, int64_t value, int minDigits=0)
Definition: SkString.cpp:488

◆ appendScalar()

void SkString::appendScalar ( SkScalar  value)
inline

Definition at line 213 of file SkString.h.

213{ this->insertScalar((size_t)-1, value); }
void insertScalar(size_t offset, SkScalar)
Definition: SkString.cpp:526

◆ appendU32()

void SkString::appendU32 ( uint32_t  value)
inline

Definition at line 210 of file SkString.h.

210{ this->insertU32((size_t)-1, value); }
void insertU32(size_t offset, uint32_t value)
Definition: SkString.cpp:494

◆ appendU64()

void SkString::appendU64 ( uint64_t  value,
int  minDigits = 0 
)
inline

Definition at line 211 of file SkString.h.

211{ this->insertU64((size_t)-1, value, minDigits); }
void insertU64(size_t offset, uint64_t value, int minDigits=0)
Definition: SkString.cpp:500

◆ appendUnichar()

void SkString::appendUnichar ( SkUnichar  uni)
inline

Definition at line 207 of file SkString.h.

207{ this->insertUnichar((size_t)-1, uni); }
void insertUnichar(size_t offset, SkUnichar)
Definition: SkString.cpp:473

◆ appendVAList()

void SkString::appendVAList ( const char  format[],
va_list  args 
)

Definition at line 557 of file SkString.cpp.

557 {
558 if (this->isEmpty()) {
559 this->printVAList(format, args);
560 return;
561 }
562
563 SkString overflow;
564 char stackBuffer[kBufferSize];
565 StringBuffer result = apply_format_string(format, args, stackBuffer, &overflow);
566
567 this->append(result.fText, result.fLength);
568}
static const size_t kBufferSize
Definition: SkString.cpp:27
static StringBuffer apply_format_string(const char *format, va_list args, char(&stackBuffer)[SIZE], SkString *heapBuffer) SK_PRINTF_LIKE(1
void void printVAList(const char format[], va_list) SK_PRINTF_LIKE(2
Definition: SkString.cpp:541
bool isEmpty() const
Definition: SkString.h:130
void append(const char text[])
Definition: SkString.h:203
GAsyncResult * result
char * fText
Definition: SkString.cpp:30

◆ c_str()

const char * SkString::c_str ( ) const
inline

Definition at line 133 of file SkString.h.

133{ return fRec->data(); }

◆ contains() [1/2]

bool SkString::contains ( const char  subchar) const
inline

Definition at line 155 of file SkString.h.

155 {
156 return SkStrContains(fRec->data(), subchar);
157 }
static bool SkStrContains(const char string[], const char substring[])
Definition: SkString.h:53

◆ contains() [2/2]

bool SkString::contains ( const char  substring[]) const
inline

Definition at line 152 of file SkString.h.

152 {
153 return SkStrContains(fRec->data(), substring);
154 }

◆ data() [1/2]

char * SkString::data ( )

Definition at line 363 of file SkString.cpp.

363 {
364 this->validate();
365
366 if (fRec->fLength) {
367 if (!fRec->unique()) {
368 fRec = Rec::Make(fRec->data(), fRec->fLength);
369 }
370 }
371 return fRec->data();
372}

◆ data() [2/2]

const char * SkString::data ( ) const
inline

Definition at line 132 of file SkString.h.

132{ return fRec->data(); }

◆ endsWith() [1/2]

bool SkString::endsWith ( const char  suffixChar) const
inline

Definition at line 149 of file SkString.h.

149 {
150 return SkStrEndsWith(fRec->data(), suffixChar);
151 }
bool SkStrEndsWith(const char string[], const char suffixStr[])
Definition: SkString.cpp:68

◆ endsWith() [2/2]

bool SkString::endsWith ( const char  suffixStr[]) const
inline

Definition at line 146 of file SkString.h.

146 {
147 return SkStrEndsWith(fRec->data(), suffixStr);
148 }

◆ equals() [1/3]

bool SkString::equals ( const char  text[]) const

Definition at line 328 of file SkString.cpp.

328 {
329 return this->equals(text, text ? strlen(text) : 0);
330}
bool equals(const SkString &) const
Definition: SkString.cpp:324

◆ equals() [2/3]

bool SkString::equals ( const char  text[],
size_t  len 
) const

Definition at line 332 of file SkString.cpp.

332 {
333 SkASSERT(len == 0 || text != nullptr);
334
335 return fRec->fLength == len && !sk_careful_memcmp(fRec->data(), text, len);
336}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static int sk_careful_memcmp(const void *a, const void *b, size_t len)
Definition: SkMalloc.h:143

◆ equals() [3/3]

bool SkString::equals ( const SkString src) const

Definition at line 324 of file SkString.cpp.

324 {
325 return fRec == src.fRec || this->equals(src.c_str(), src.size());
326}

◆ find()

int SkString::find ( const char  substring[]) const
inline

Definition at line 158 of file SkString.h.

158 {
159 return SkStrFind(fRec->data(), substring);
160 }
static int SkStrFind(const char string[], const char substring[])
Definition: SkString.h:41

◆ findLastOf()

int SkString::findLastOf ( const char  subchar) const
inline

Definition at line 161 of file SkString.h.

161 {
162 return SkStrFindLastOf(fRec->data(), subchar);
163 }
static int SkStrFindLastOf(const char string[], const char subchar)
Definition: SkString.h:47

◆ insert() [1/4]

void SkString::insert ( size_t  offset,
const char  text[] 
)

Definition at line 415 of file SkString.cpp.

415 {
416 this->insert(offset, text, text ? strlen(text) : 0);
417}
SeparatedVector2 offset

◆ insert() [2/4]

void SkString::insert ( size_t  offset,
const char  text[],
size_t  len 
)

Definition at line 419 of file SkString.cpp.

419 {
420 if (len) {
421 size_t length = fRec->fLength;
422 if (offset > length) {
423 offset = length;
424 }
425
426 // Check if length + len exceeds 32bits, we trim len
428 if (0 == len) {
429 return;
430 }
431
432 /* If we're the only owner, and we have room in our allocation for the insert,
433 do it in place, rather than allocating a new buffer.
434
435 To know we have room, compare the allocated sizes
436 beforeAlloc = SkAlign4(length + 1)
437 afterAlloc = SkAligh4(length + 1 + len)
438 but SkAlign4(x) is (x + 3) >> 2 << 2
439 which is equivalent for testing to (length + 1 + 3) >> 2 == (length + 1 + 3 + len) >> 2
440 and we can then eliminate the +1+3 since that doesn't affec the answer
441 */
442 if (fRec->unique() && (length >> 2) == ((length + len) >> 2)) {
443 char* dst = this->data();
444
445 if (offset < length) {
446 memmove(dst + offset + len, dst + offset, length - offset);
447 }
448 memcpy(dst + offset, text, len);
449
450 dst[length + len] = 0;
451 fRec->fLength = SkToU32(length + len);
452 } else {
453 /* Seems we should use realloc here, since that is safe if it fails
454 (we have the original data), and might be faster than alloc/copy/free.
455 */
456 SkString tmp(fRec->fLength + len);
457 char* dst = tmp.data();
458
459 if (offset > 0) {
460 memcpy(dst, fRec->data(), offset);
461 }
462 memcpy(dst + offset, text, len);
463 if (offset < fRec->fLength) {
464 memcpy(dst + offset + len, fRec->data() + offset,
465 fRec->fLength - offset);
466 }
467
468 this->swap(tmp);
469 }
470 }
471}
static size_t check_add32(size_t base, size_t extra)
Definition: SkString.cpp:206
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
const char * data() const
Definition: SkString.h:132
void swap(SkString &other)
Definition: SkString.cpp:619
size_t length
dst
Definition: cp.py:12

◆ insert() [3/4]

void SkString::insert ( size_t  offset,
const SkString str 
)
inline

Definition at line 193 of file SkString.h.

193{ this->insert(offset, str.c_str(), str.size()); }

◆ insert() [4/4]

void SkString::insert ( size_t  offset,
std::string_view  str 
)
inline

Definition at line 194 of file SkString.h.

194{ this->insert(offset, str.data(), str.size()); }

◆ insertHex()

void SkString::insertHex ( size_t  offset,
uint32_t  value,
int  minDigits = 0 
)

Definition at line 506 of file SkString.cpp.

506 {
507 minDigits = SkTPin(minDigits, 0, 8);
508
509 char buffer[8];
510 char* p = buffer + sizeof(buffer);
511
512 do {
513 *--p = SkHexadecimalDigits::gUpper[hex & 0xF];
514 hex >>= 4;
515 minDigits -= 1;
516 } while (hex != 0);
517
518 while (--minDigits >= 0) {
519 *--p = '0';
520 }
521
522 SkASSERT(p >= buffer);
523 this->insert(offset, p, buffer + sizeof(buffer) - p);
524}
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
const char gUpper[16]
Definition: SkUtils.cpp:10
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ insertS32()

void SkString::insertS32 ( size_t  offset,
int32_t  value 
)

Definition at line 482 of file SkString.cpp.

482 {
484 char* stop = SkStrAppendS32(buffer, dec);
485 this->insert(offset, buffer, stop - buffer);
486}
char * SkStrAppendS32(char string[], int32_t dec)
Definition: SkString.cpp:120
static constexpr int kSkStrAppendS32_MaxSize
Definition: SkString.h:89

◆ insertS64()

void SkString::insertS64 ( size_t  offset,
int64_t  value,
int  minDigits = 0 
)

Definition at line 488 of file SkString.cpp.

488 {
490 char* stop = SkStrAppendS64(buffer, dec, minDigits);
491 this->insert(offset, buffer, stop - buffer);
492}
char * SkStrAppendS64(char string[], int64_t dec, int minDigits)
Definition: SkString.cpp:155
static constexpr int kSkStrAppendS64_MaxSize
Definition: SkString.h:91

◆ insertScalar()

void SkString::insertScalar ( size_t  offset,
SkScalar  value 
)

Definition at line 526 of file SkString.cpp.

526 {
528 char* stop = SkStrAppendScalar(buffer, value);
529 this->insert(offset, buffer, stop - buffer);
530}
char * SkStrAppendScalar(char string[], SkScalar value)
Definition: SkString.cpp:164
static constexpr int kSkStrAppendScalar_MaxSize
Definition: SkString.h:101

◆ insertU32()

void SkString::insertU32 ( size_t  offset,
uint32_t  value 
)

Definition at line 494 of file SkString.cpp.

494 {
496 char* stop = SkStrAppendU32(buffer, dec);
497 this->insert(offset, buffer, stop - buffer);
498}
char * SkStrAppendU32(char string[], uint32_t dec)
Definition: SkString.cpp:100
static constexpr int kSkStrAppendU32_MaxSize
Definition: SkString.h:84

◆ insertU64()

void SkString::insertU64 ( size_t  offset,
uint64_t  value,
int  minDigits = 0 
)

Definition at line 500 of file SkString.cpp.

500 {
502 char* stop = SkStrAppendU64(buffer, dec, minDigits);
503 this->insert(offset, buffer, stop - buffer);
504}
char * SkStrAppendU64(char string[], uint64_t dec, int minDigits)
Definition: SkString.cpp:129
static constexpr int kSkStrAppendU64_MaxSize
Definition: SkString.h:86

◆ insertUnichar()

void SkString::insertUnichar ( size_t  offset,
SkUnichar  uni 
)

Definition at line 473 of file SkString.cpp.

473 {
475 size_t len = SkUTF::ToUTF8(uni, buffer);
476
477 if (len) {
478 this->insert(offset, buffer, len);
479 }
480}
SK_SPI size_t ToUTF8(SkUnichar uni, char utf8[kMaxBytesInUTF8Sequence]=nullptr)
constexpr unsigned kMaxBytesInUTF8Sequence
Definition: SkUTF.h:59

◆ isEmpty()

bool SkString::isEmpty ( ) const
inline

Definition at line 130 of file SkString.h.

130{ return 0 == fRec->fLength; }

◆ operator+=() [1/3]

SkString & SkString::operator+= ( const char  c)
inline

Definition at line 236 of file SkString.h.

236{ this->append(&c, 1); return *this; }

◆ operator+=() [2/3]

SkString & SkString::operator+= ( const char  text[])
inline

Definition at line 235 of file SkString.h.

235{ this->append(text); return *this; }

◆ operator+=() [3/3]

SkString & SkString::operator+= ( const SkString s)
inline

Definition at line 234 of file SkString.h.

234{ this->append(s); return *this; }

◆ operator=() [1/3]

SkString & SkString::operator= ( const char  text[])

Definition at line 353 of file SkString.cpp.

353 {
354 this->validate();
355 return *this = SkString(text);
356}

◆ operator=() [2/3]

SkString & SkString::operator= ( const SkString src)

Definition at line 338 of file SkString.cpp.

338 {
339 this->validate();
340 fRec = src.fRec; // sk_sp<Rec>::operator=(const sk_sp<Ref>&) checks for self-assignment.
341 return *this;
342}

◆ operator=() [3/3]

SkString & SkString::operator= ( SkString &&  src)

Definition at line 344 of file SkString.cpp.

344 {
345 this->validate();
346
347 if (fRec != src.fRec) {
348 this->swap(src);
349 }
350 return *this;
351}

◆ operator[]() [1/2]

char & SkString::operator[] ( size_t  n)
inline

Definition at line 179 of file SkString.h.

179{ return this->data()[n]; }

◆ operator[]() [2/2]

char SkString::operator[] ( size_t  n) const
inline

Definition at line 134 of file SkString.h.

134{ return this->c_str()[n]; }

◆ prepend() [1/4]

void SkString::prepend ( const char  text[])
inline

Definition at line 215 of file SkString.h.

215{ this->insert(0, text); }

◆ prepend() [2/4]

void SkString::prepend ( const char  text[],
size_t  len 
)
inline

Definition at line 216 of file SkString.h.

216{ this->insert(0, text, len); }

◆ prepend() [3/4]

void SkString::prepend ( const SkString str)
inline

Definition at line 217 of file SkString.h.

217{ this->insert(0, str.c_str(), str.size()); }

◆ prepend() [4/4]

void SkString::prepend ( std::string_view  str)
inline

Definition at line 218 of file SkString.h.

218{ this->insert(0, str.data(), str.size()); }

◆ prependf()

void SkString::prependf ( const char  format[],
  ... 
)

Definition at line 570 of file SkString.cpp.

570 {
571 va_list args;
573 this->prependVAList(format, args);
574 va_end(args);
575}
void void void void void void prependVAList(const char format[], va_list) SK_PRINTF_LIKE(2
Definition: SkString.cpp:577

◆ prependHex()

void SkString::prependHex ( uint32_t  value,
int  minDigits = 0 
)
inline

Definition at line 222 of file SkString.h.

222{ this->insertHex(0, value, minDigits); }

◆ prependS32()

void SkString::prependS32 ( int32_t  value)
inline

Definition at line 220 of file SkString.h.

220{ this->insertS32(0, value); }

◆ prependS64()

void SkString::prependS64 ( int32_t  value,
int  minDigits = 0 
)
inline

Definition at line 221 of file SkString.h.

221{ this->insertS64(0, value, minDigits); }

◆ prependScalar()

void SkString::prependScalar ( SkScalar  value)
inline

Definition at line 223 of file SkString.h.

223{ this->insertScalar((size_t)-1, value); }

◆ prependUnichar()

void SkString::prependUnichar ( SkUnichar  uni)
inline

Definition at line 219 of file SkString.h.

219{ this->insertUnichar(0, uni); }

◆ prependVAList()

void SkString::prependVAList ( const char  format[],
va_list  args 
)

Definition at line 577 of file SkString.cpp.

577 {
578 if (this->isEmpty()) {
579 this->printVAList(format, args);
580 return;
581 }
582
583 SkString overflow;
584 char stackBuffer[kBufferSize];
585 StringBuffer result = apply_format_string(format, args, stackBuffer, &overflow);
586
587 this->prepend(result.fText, result.fLength);
588}
void prepend(const char text[])
Definition: SkString.h:215

◆ printf()

void SkString::printf ( const char  format[],
  ... 
)

Definition at line 534 of file SkString.cpp.

534 {
535 va_list args;
537 this->printVAList(format, args);
538 va_end(args);
539}

◆ printVAList()

void SkString::printVAList ( const char  format[],
va_list  args 
)

Definition at line 541 of file SkString.cpp.

541 {
542 char stackBuffer[kBufferSize];
543 StringBuffer result = apply_format_string(format, args, stackBuffer, this);
544
545 if (result.fText == stackBuffer) {
546 this->set(result.fText, result.fLength);
547 }
548}
void set(const SkString &src)
Definition: SkString.h:186

◆ remove()

void SkString::remove ( size_t  offset,
size_t  length 
)

Definition at line 592 of file SkString.cpp.

592 {
593 size_t size = this->size();
594
595 if (offset < size) {
596 if (length > size - offset) {
597 length = size - offset;
598 }
599 SkASSERT(length <= size);
601 if (length > 0) {
602 SkString tmp(size - length);
603 char* dst = tmp.data();
604 const char* src = this->c_str();
605
606 if (offset) {
607 memcpy(dst, src, offset);
608 }
609 size_t tail = size - (offset + length);
610 if (tail) {
611 memcpy(dst + offset, src + (offset + length), tail);
612 }
613 SkASSERT(dst[tmp.size()] == 0);
614 this->swap(tmp);
615 }
616 }
617}

◆ reset()

void SkString::reset ( )

Definition at line 358 of file SkString.cpp.

358 {
359 this->validate();
360 fRec.reset(const_cast<Rec*>(&gEmptyRec));
361}
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310

◆ resize()

void SkString::resize ( size_t  len)

String contents are preserved on resize. (For destructive resize, set(nullptr, length).) resize automatically reserves an extra byte at the end of the buffer for a null terminator.

Definition at line 374 of file SkString.cpp.

374 {
376 if (0 == len) {
377 this->reset();
378 } else if (fRec->unique() && ((len >> 2) <= (fRec->fLength >> 2))) {
379 // Use less of the buffer we have without allocating a smaller one.
380 char* p = this->data();
381 p[len] = '\0';
382 fRec->fLength = SkToU32(len);
383 } else {
384 SkString newString(len);
385 char* dest = newString.data();
386 int copyLen = std::min<uint32_t>(len, this->size());
387 memcpy(dest, this->c_str(), copyLen);
388 dest[copyLen] = '\0';
389 this->swap(newString);
390 }
391}
static uint32_t trim_size_t_to_u32(size_t value)
Definition: SkString.cpp:197
void reset()
Definition: SkString.cpp:358
dest
Definition: zip.py:79

◆ set() [1/4]

void SkString::set ( const char  text[])

Definition at line 393 of file SkString.cpp.

393 {
394 this->set(text, text ? strlen(text) : 0);
395}

◆ set() [2/4]

void SkString::set ( const char  text[],
size_t  len 
)

Definition at line 397 of file SkString.cpp.

397 {
399 if (0 == len) {
400 this->reset();
401 } else if (fRec->unique() && ((len >> 2) <= (fRec->fLength >> 2))) {
402 // Use less of the buffer we have without allocating a smaller one.
403 char* p = this->data();
404 if (text) {
405 memcpy(p, text, len);
406 }
407 p[len] = '\0';
408 fRec->fLength = SkToU32(len);
409 } else {
410 SkString tmp(text, len);
411 this->swap(tmp);
412 }
413}

◆ set() [3/4]

void SkString::set ( const SkString src)
inline

Definition at line 186 of file SkString.h.

186{ *this = src; }

◆ set() [4/4]

void SkString::set ( std::string_view  str)
inline

Definition at line 189 of file SkString.h.

189{ this->set(str.data(), str.size()); }

◆ size()

size_t SkString::size ( ) const
inline

Definition at line 131 of file SkString.h.

131{ return (size_t) fRec->fLength; }

◆ startsWith() [1/2]

bool SkString::startsWith ( const char  prefixChar) const
inline

Definition at line 143 of file SkString.h.

143 {
144 return SkStrStartsWith(fRec->data(), prefixChar);
145 }
static bool SkStrStartsWith(const char string[], const char prefixStr[])
Definition: SkString.h:26

◆ startsWith() [2/2]

bool SkString::startsWith ( const char  prefixStr[]) const
inline

Definition at line 140 of file SkString.h.

140 {
141 return SkStrStartsWith(fRec->data(), prefixStr);
142 }

◆ swap()

void SkString::swap ( SkString other)

Swap contents between this and other. This function is guaranteed to never fail or throw.

Definition at line 619 of file SkString.cpp.

619 {
620 this->validate();
621 other.validate();
622
623 using std::swap;
624 swap(fRec, other.fRec);
625}
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const SkString a,
const SkString b 
)
friend

Definition at line 168 of file SkString.h.

168 {
169 return !a.equals(b);
170 }
static bool b
struct MyStruct a[10]

◆ operator==

bool operator== ( const SkString a,
const SkString b 
)
friend

Definition at line 165 of file SkString.h.

165 {
166 return a.equals(b);
167 }

The documentation for this class was generated from the following files: