Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Enumerations | Functions
SkStringUtils.h File Reference
#include "include/core/SkScalar.h"
#include "include/core/SkString.h"
#include "include/private/base/SkTArray.h"
#include <cstddef>
#include <cstdint>

Go to the source code of this file.

Macros

#define SK_strcasecmp   strcasecmp
 

Enumerations

enum  SkScalarAsStringType { kDec_SkScalarAsStringType , kHex_SkScalarAsStringType }
 
enum  SkStrSplitMode { kStrict_SkStrSplitMode , kCoalesce_SkStrSplitMode }
 

Functions

void SkAppendScalar (SkString *, SkScalar, SkScalarAsStringType)
 
static void SkAppendScalarDec (SkString *str, SkScalar value)
 
static void SkAppendScalarHex (SkString *str, SkScalar value)
 
SkString SkTabString (const SkString &string, int tabCnt)
 
SkString SkStringFromUTF16 (const uint16_t *src, size_t count)
 
void SkStrSplit (const char *str, const char *delimiters, SkStrSplitMode splitMode, skia_private::TArray< SkString > *out)
 
void SkStrSplit (const char *str, const char *delimiters, skia_private::TArray< SkString > *out)
 

Macro Definition Documentation

◆ SK_strcasecmp

#define SK_strcasecmp   strcasecmp

Definition at line 41 of file SkStringUtils.h.

Enumeration Type Documentation

◆ SkScalarAsStringType

Enumerator
kDec_SkScalarAsStringType 
kHex_SkScalarAsStringType 

Definition at line 18 of file SkStringUtils.h.

18 {
21};
@ kHex_SkScalarAsStringType
@ kDec_SkScalarAsStringType

◆ SkStrSplitMode

Enumerator
kStrict_SkStrSplitMode 
kCoalesce_SkStrSplitMode 

Definition at line 44 of file SkStringUtils.h.

44 {
45 // Strictly return all results. If the input is ",," and the separator is ',' this will return
46 // an array of three empty strings.
48
49 // Only nonempty results will be added to the results. Multiple separators will be
50 // coalesced. Separators at the beginning and end of the input will be ignored. If the input is
51 // ",," and the separator is ',', this will return an empty vector.
53};
@ kStrict_SkStrSplitMode
@ kCoalesce_SkStrSplitMode

Function Documentation

◆ SkAppendScalar()

void SkAppendScalar ( SkString str,
SkScalar  value,
SkScalarAsStringType  asType 
)

Definition at line 20 of file SkStringUtils.cpp.

20 {
21 switch (asType) {
23 str->appendf("SkBits2Float(0x%08x)", SkFloat2Bits(value));
24 break;
26 SkString tmp;
27 tmp.printf("%.9g", value);
28 if (tmp.contains('.')) {
29 tmp.appendUnichar('f');
30 }
31 str->append(tmp);
32 break;
33 }
34 }
35}
static uint32_t SkFloat2Bits(float value)
Definition SkFloatBits.h:41
void appendUnichar(SkUnichar uni)
Definition SkString.h:207
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
void append(const char text[])
Definition SkString.h:203
bool contains(const char substring[]) const
Definition SkString.h:152
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550

◆ SkAppendScalarDec()

static void SkAppendScalarDec ( SkString str,
SkScalar  value 
)
inlinestatic

Definition at line 25 of file SkStringUtils.h.

25 {
27}
void SkAppendScalar(SkString *, SkScalar, SkScalarAsStringType)

◆ SkAppendScalarHex()

static void SkAppendScalarHex ( SkString str,
SkScalar  value 
)
inlinestatic

Definition at line 29 of file SkStringUtils.h.

29 {
31}

◆ SkStringFromUTF16()

SkString SkStringFromUTF16 ( const uint16_t *  src,
size_t  count 
)

Definition at line 64 of file SkStringUtils.cpp.

64 {
65 SkString ret;
66 const uint16_t* stop = src + count;
67 if (count > 0) {
68 SkASSERT(src);
69 size_t n = 0;
70 const uint16_t* end = src + count;
71 for (const uint16_t* ptr = src; ptr < end;) {
72 const uint16_t* last = ptr;
73 SkUnichar u = SkUTF::NextUTF16(&ptr, stop);
74 size_t s = SkUTF::ToUTF8(u);
75 if (n > UINT32_MAX - s) {
76 end = last; // truncate input string
77 break;
78 }
79 n += s;
80 }
81 ret = SkString(n);
82 char* out = ret.data();
83 for (const uint16_t* ptr = src; ptr < end;) {
84 out += SkUTF::ToUTF8(SkUTF::NextUTF16(&ptr, stop), out);
85 }
86 SkASSERT(out == ret.data() + n);
87 }
88 return ret;
89}
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
int32_t SkUnichar
Definition SkTypes.h:175
const char * data() const
Definition SkString.h:132
struct MyStruct s
glong glong end
SK_SPI size_t ToUTF8(SkUnichar uni, char utf8[kMaxBytesInUTF8Sequence]=nullptr)
SK_SPI SkUnichar NextUTF16(const uint16_t **ptr, const uint16_t *end)
Definition SkUTF.cpp:159

◆ SkStrSplit() [1/2]

void SkStrSplit ( const char *  str,
const char *  delimiters,
skia_private::TArray< SkString > *  out 
)
inline

Definition at line 61 of file SkStringUtils.h.

62 {
63 SkStrSplit(str, delimiters, kCoalesce_SkStrSplitMode, out);
64}
void SkStrSplit(const char *str, const char *delimiters, SkStrSplitMode splitMode, skia_private::TArray< SkString > *out)

◆ SkStrSplit() [2/2]

void SkStrSplit ( const char *  str,
const char *  delimiters,
SkStrSplitMode  splitMode,
skia_private::TArray< SkString > *  out 
)

Definition at line 91 of file SkStringUtils.cpp.

94 {
95 if (splitMode == kCoalesce_SkStrSplitMode) {
96 // Skip any delimiters.
97 str += strspn(str, delimiters);
98 }
99 if (!*str) {
100 return;
101 }
102
103 while (true) {
104 // Find a token.
105 const size_t len = strcspn(str, delimiters);
106 if (splitMode == kStrict_SkStrSplitMode || len > 0) {
107 out->push_back().set(str, len);
108 str += len;
109 }
110
111 if (!*str) {
112 return;
113 }
114 if (splitMode == kCoalesce_SkStrSplitMode) {
115 // Skip any delimiters.
116 str += strspn(str, delimiters);
117 } else {
118 // Skip one delimiter.
119 str += 1;
120 }
121 }
122}

◆ SkTabString()

SkString SkTabString ( const SkString string,
int  tabCnt 
)

Indents every non-empty line of the string by tabCnt tabs

Definition at line 37 of file SkStringUtils.cpp.

37 {
38 if (tabCnt <= 0) {
39 return string;
40 }
41 SkString tabs;
42 for (int i = 0; i < tabCnt; ++i) {
43 tabs.append("\t");
44 }
46 static const char newline[] = "\n";
47 const char* input = string.c_str();
48 int nextNL = SkStrFind(input, newline);
49 while (nextNL >= 0) {
50 if (nextNL > 0) {
51 result.append(tabs);
52 }
53 result.append(input, nextNL + 1);
54 input += nextNL + 1;
55 nextNL = SkStrFind(input, newline);
56 }
57 if (*input != '\0') {
58 result.append(tabs);
59 result.append(input);
60 }
61 return result;
62}
static int SkStrFind(const char string[], const char substring[])
Definition SkString.h:41
const char * c_str() const
Definition SkString.h:133
GAsyncResult * result