Flutter Engine
The Flutter Engine
Static Public Member Functions | List of all members
SkParse Class Reference

#include <SkParse.h>

Static Public Member Functions

static int Count (const char str[])
 
static int Count (const char str[], char separator)
 
static const char * FindColor (const char str[], SkColor *value)
 
static const char * FindHex (const char str[], uint32_t *value)
 
static const char * FindMSec (const char str[], SkMSec *value)
 
static const char * FindNamedColor (const char str[], size_t len, SkColor *color)
 
static const char * FindS32 (const char str[], int32_t *value)
 
static const char * FindScalar (const char str[], SkScalar *value)
 
static const char * FindScalars (const char str[], SkScalar value[], int count)
 
static bool FindBool (const char str[], bool *value)
 
static int FindList (const char str[], const char list[])
 

Detailed Description

Definition at line 20 of file SkParse.h.

Member Function Documentation

◆ Count() [1/2]

int SkParse::Count ( const char  str[])
static

Definition at line 72 of file SkParse.cpp.

73{
74 char c;
75 int count = 0;
76 goto skipLeading;
77 do {
78 count++;
79 do {
80 if ((c = *str++) == '\0')
81 goto goHome;
82 } while (is_sep(c) == false);
83skipLeading:
84 do {
85 if ((c = *str++) == '\0')
86 goto goHome;
87 } while (is_sep(c));
88 } while (true);
89goHome:
90 return count;
91}
int count
Definition: FontMgrTest.cpp:50
static bool is_sep(int c)
Definition: SkParse.cpp:34

◆ Count() [2/2]

int SkParse::Count ( const char  str[],
char  separator 
)
static

Definition at line 93 of file SkParse.cpp.

94{
95 char c;
96 int count = 0;
97 goto skipLeading;
98 do {
99 count++;
100 do {
101 if ((c = *str++) == '\0')
102 goto goHome;
103 } while (c != separator);
104skipLeading:
105 do {
106 if ((c = *str++) == '\0')
107 goto goHome;
108 } while (c == separator);
109 } while (true);
110goHome:
111 return count;
112}

◆ FindBool()

bool SkParse::FindBool ( const char  str[],
bool *  value 
)
static

Definition at line 260 of file SkParse.cpp.

261{
262 static const char* gYes[] = { "yes", "1", "true" };
263 static const char* gNo[] = { "no", "0", "false" };
264
265 if (lookup_str(str, gYes, std::size(gYes)))
266 {
267 if (value) *value = true;
268 return true;
269 }
270 else if (lookup_str(str, gNo, std::size(gNo)))
271 {
272 if (value) *value = false;
273 return true;
274 }
275 return false;
276}
static bool lookup_str(const char str[], const char **table, int count)
Definition: SkParse.cpp:252
uint8_t value
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ FindColor()

const char * SkParse::FindColor ( const char  str[],
SkColor value 
)
static

Definition at line 349 of file SkParseColor.cpp.

349 {
350 unsigned int oldAlpha = SkColorGetA(*colorPtr);
351 if (value[0] == '#') {
352 uint32_t hex;
353 const char* end = SkParse::FindHex(value + 1, &hex);
354// SkASSERT(end);
355 if (end == nullptr)
356 return end;
357 size_t len = end - value - 1;
358 if (len == 3 || len == 4) {
359 unsigned a = len == 4 ? nib2byte(hex >> 12) : oldAlpha;
360 unsigned r = nib2byte((hex >> 8) & 0xF);
361 unsigned g = nib2byte((hex >> 4) & 0xF);
362 unsigned b = nib2byte(hex & 0xF);
363 *colorPtr = SkColorSetARGB(a, r, g, b);
364 return end;
365 } else if (len == 6 || len == 8) {
366 if (len == 6)
367 hex |= oldAlpha << 24;
368 *colorPtr = hex;
369 return end;
370 } else {
371// SkASSERT(0);
372 return nullptr;
373 }
374// } else if (strchr(value, ',')) {
375// SkScalar array[4];
376// int count = count_separators(value, ",") + 1; // !!! count commas, add 1
377// SkASSERT(count == 3 || count == 4);
378// array[0] = SK_Scalar1 * 255;
379// const char* end = SkParse::FindScalars(value, &array[4 - count], count);
380// if (end == nullptr)
381// return nullptr;
382 // !!! range check for errors?
383// *colorPtr = SkColorSetARGB(SkScalarRoundToInt(array[0]), SkScalarRoundToInt(array[1]),
384// SkScalarRoundToInt(array[2]), SkScalarRoundToInt(array[3]));
385// return end;
386 } else
387 return FindNamedColor(value, strlen(value), colorPtr);
388}
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
#define SkColorGetA(color)
Definition: SkColor.h:61
static unsigned nib2byte(unsigned n)
static const char * FindHex(const char str[], uint32_t *value)
Definition: SkParse.cpp:114
static const char * FindNamedColor(const char str[], size_t len, SkColor *color)
static bool b
struct MyStruct a[10]
glong glong end

◆ FindHex()

const char * SkParse::FindHex ( const char  str[],
uint32_t *  value 
)
static

Definition at line 114 of file SkParse.cpp.

115{
116 SkASSERT(str);
117 str = skip_ws(str);
118
119 if (!is_hex(*str))
120 return nullptr;
121
122 uint32_t n = 0;
123 int max_digits = 8;
124 int digit;
125
126 while ((digit = to_hex(*str)) >= 0)
127 {
128 if (--max_digits < 0)
129 return nullptr;
130 n = (n << 4) | digit;
131 str += 1;
132 }
133
134 if (*str == 0 || is_ws(*str))
135 {
136 if (value)
137 *value = n;
138 return str;
139 }
140 return nullptr;
141}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool is_ws(int c)
Definition: SkParse.cpp:24
static bool is_hex(int c)
Definition: SkParse.cpp:51
static const char * skip_ws(const char str[])
Definition: SkParse.cpp:56
static int to_hex(int c)
Definition: SkParse.cpp:39

◆ FindList()

int SkParse::FindList ( const char  str[],
const char  list[] 
)
static

Definition at line 278 of file SkParse.cpp.

279{
280 size_t len = strlen(target);
281 int index = 0;
282
283 for (;;)
284 {
285 const char* end = strchr(list, ',');
286 size_t entryLen;
287
288 if (end == nullptr) // last entry
289 entryLen = strlen(list);
290 else
291 entryLen = end - list;
292
293 if (entryLen == len && memcmp(target, list, len) == 0)
294 return index;
295 if (end == nullptr)
296 break;
297
298 list = end + 1; // skip the ','
299 index += 1;
300 }
301 return -1;
302}
uint32_t * target

◆ FindMSec()

const char * SkParse::FindMSec ( const char  str[],
SkMSec value 
)
static

Definition at line 177 of file SkParse.cpp.

178{
179 SkASSERT(str);
180 str = skip_ws(str);
181
182 int sign = 0;
183 if (*str == '-')
184 {
185 sign = -1;
186 str += 1;
187 }
188
189 if (!is_digit(*str))
190 return nullptr;
191
192 int n = 0;
193 while (is_digit(*str))
194 {
195 n = 10*n + *str - '0';
196 str += 1;
197 }
198 int remaining10s = 3;
199 if (*str == '.') {
200 str++;
201 while (is_digit(*str))
202 {
203 n = 10*n + *str - '0';
204 str += 1;
205 if (--remaining10s == 0)
206 break;
207 }
208 }
209 while (--remaining10s >= 0)
210 n *= 10;
211 if (value)
212 *value = (n ^ sign) - sign;
213 return str;
214}
static bool is_digit(int c)
Definition: SkParse.cpp:29
static int sign(SkScalar x)
Definition: SkPath.cpp:2205

◆ FindNamedColor()

const char * SkParse::FindNamedColor ( const char  str[],
size_t  len,
SkColor color 
)
static

Definition at line 306 of file SkParseColor.cpp.

306 {
307 const auto rec = std::lower_bound(std::begin(gColorNames),
308 std::end (gColorNames),
309 name, // key
310 [](const char* name, const char* key) {
311 return strcmp(name, key) < 0;
312 });
313
314 if (rec == std::end(gColorNames) || 0 != strcmp(name, *rec)) {
315 return nullptr;
316 }
317
318 if (color) {
319 int index = rec - gColorNames;
320 *color = SkColorSetRGB(gColors[index].r, gColors[index].g, gColors[index].b);
321 }
322
323 return name + strlen(*rec);
324}
#define SkColorSetRGB(r, g, b)
Definition: SkColor.h:57
static constexpr const char * gColorNames[]
static constexpr struct ColorRec gColors[]
DlColor color
static const char * begin(const StringSlice &s)
Definition: editor.cpp:252
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32

◆ FindS32()

const char * SkParse::FindS32 ( const char  str[],
int32_t *  value 
)
static

Definition at line 143 of file SkParse.cpp.

144{
145 SkASSERT(str);
146 str = skip_ws(str);
147
148 int sign = 1;
149 int64_t maxAbsValue = std::numeric_limits<int>::max();
150 if (*str == '-')
151 {
152 sign = -1;
153 maxAbsValue = -static_cast<int64_t>(std::numeric_limits<int>::min());
154 str += 1;
155 }
156
157 if (!is_digit(*str)) {
158 return nullptr;
159 }
160
161 int64_t n = 0;
162 while (is_digit(*str))
163 {
164 n = 10*n + *str - '0';
165 if (n > maxAbsValue) {
166 return nullptr;
167 }
168
169 str += 1;
170 }
171 if (value) {
172 *value = SkToS32(sign*n);
173 }
174 return str;
175}
constexpr int32_t SkToS32(S x)
Definition: SkTo.h:25
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ FindScalar()

const char * SkParse::FindScalar ( const char  str[],
SkScalar value 
)
static

Definition at line 216 of file SkParse.cpp.

216 {
217 SkASSERT(str);
218 str = skip_ws(str);
219
220 char* stop;
221 float v = (float)strtod(str, &stop);
222 if (str == stop) {
223 return nullptr;
224 }
225 if (value) {
226 *value = v;
227 }
228 return stop;
229}

◆ FindScalars()

const char * SkParse::FindScalars ( const char  str[],
SkScalar  value[],
int  count 
)
static

Definition at line 231 of file SkParse.cpp.

232{
233 SkASSERT(count >= 0);
234
235 if (count > 0)
236 {
237 for (;;)
238 {
239 str = SkParse::FindScalar(str, value);
240 if (--count == 0 || str == nullptr)
241 break;
242
243 // keep going
244 str = skip_sep(str);
245 if (value)
246 value += 1;
247 }
248 }
249 return str;
250}
static const char * skip_sep(const char str[])
Definition: SkParse.cpp:64
static const char * FindScalar(const char str[], SkScalar *value)
Definition: SkParse.cpp:216

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