OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 goHome: | 105 goHome: |
106 return count; | 106 return count; |
107 } | 107 } |
108 | 108 |
109 const char* SkParse::FindHex(const char str[], uint32_t* value) | 109 const char* SkParse::FindHex(const char str[], uint32_t* value) |
110 { | 110 { |
111 SkASSERT(str); | 111 SkASSERT(str); |
112 str = skip_ws(str); | 112 str = skip_ws(str); |
113 | 113 |
114 if (!is_hex(*str)) | 114 if (!is_hex(*str)) |
115 return NULL; | 115 return nullptr; |
116 | 116 |
117 uint32_t n = 0; | 117 uint32_t n = 0; |
118 int max_digits = 8; | 118 int max_digits = 8; |
119 int digit; | 119 int digit; |
120 | 120 |
121 while ((digit = to_hex(*str)) >= 0) | 121 while ((digit = to_hex(*str)) >= 0) |
122 { | 122 { |
123 if (--max_digits < 0) | 123 if (--max_digits < 0) |
124 return NULL; | 124 return nullptr; |
125 n = (n << 4) | digit; | 125 n = (n << 4) | digit; |
126 str += 1; | 126 str += 1; |
127 } | 127 } |
128 | 128 |
129 if (*str == 0 || is_ws(*str)) | 129 if (*str == 0 || is_ws(*str)) |
130 { | 130 { |
131 if (value) | 131 if (value) |
132 *value = n; | 132 *value = n; |
133 return str; | 133 return str; |
134 } | 134 } |
135 return NULL; | 135 return nullptr; |
136 } | 136 } |
137 | 137 |
138 const char* SkParse::FindS32(const char str[], int32_t* value) | 138 const char* SkParse::FindS32(const char str[], int32_t* value) |
139 { | 139 { |
140 SkASSERT(str); | 140 SkASSERT(str); |
141 str = skip_ws(str); | 141 str = skip_ws(str); |
142 | 142 |
143 int sign = 0; | 143 int sign = 0; |
144 if (*str == '-') | 144 if (*str == '-') |
145 { | 145 { |
146 sign = -1; | 146 sign = -1; |
147 str += 1; | 147 str += 1; |
148 } | 148 } |
149 | 149 |
150 if (!is_digit(*str)) | 150 if (!is_digit(*str)) |
151 return NULL; | 151 return nullptr; |
152 | 152 |
153 int n = 0; | 153 int n = 0; |
154 while (is_digit(*str)) | 154 while (is_digit(*str)) |
155 { | 155 { |
156 n = 10*n + *str - '0'; | 156 n = 10*n + *str - '0'; |
157 str += 1; | 157 str += 1; |
158 } | 158 } |
159 if (value) | 159 if (value) |
160 *value = (n ^ sign) - sign; | 160 *value = (n ^ sign) - sign; |
161 return str; | 161 return str; |
162 } | 162 } |
163 | 163 |
164 const char* SkParse::FindMSec(const char str[], SkMSec* value) | 164 const char* SkParse::FindMSec(const char str[], SkMSec* value) |
165 { | 165 { |
166 SkASSERT(str); | 166 SkASSERT(str); |
167 str = skip_ws(str); | 167 str = skip_ws(str); |
168 | 168 |
169 int sign = 0; | 169 int sign = 0; |
170 if (*str == '-') | 170 if (*str == '-') |
171 { | 171 { |
172 sign = -1; | 172 sign = -1; |
173 str += 1; | 173 str += 1; |
174 } | 174 } |
175 | 175 |
176 if (!is_digit(*str)) | 176 if (!is_digit(*str)) |
177 return NULL; | 177 return nullptr; |
178 | 178 |
179 int n = 0; | 179 int n = 0; |
180 while (is_digit(*str)) | 180 while (is_digit(*str)) |
181 { | 181 { |
182 n = 10*n + *str - '0'; | 182 n = 10*n + *str - '0'; |
183 str += 1; | 183 str += 1; |
184 } | 184 } |
185 int remaining10s = 3; | 185 int remaining10s = 3; |
186 if (*str == '.') { | 186 if (*str == '.') { |
187 str++; | 187 str++; |
(...skipping 12 matching lines...) Expand all Loading... |
200 return str; | 200 return str; |
201 } | 201 } |
202 | 202 |
203 const char* SkParse::FindScalar(const char str[], SkScalar* value) { | 203 const char* SkParse::FindScalar(const char str[], SkScalar* value) { |
204 SkASSERT(str); | 204 SkASSERT(str); |
205 str = skip_ws(str); | 205 str = skip_ws(str); |
206 | 206 |
207 char* stop; | 207 char* stop; |
208 float v = (float)strtod(str, &stop); | 208 float v = (float)strtod(str, &stop); |
209 if (str == stop) { | 209 if (str == stop) { |
210 return NULL; | 210 return nullptr; |
211 } | 211 } |
212 if (value) { | 212 if (value) { |
213 *value = v; | 213 *value = v; |
214 } | 214 } |
215 return stop; | 215 return stop; |
216 } | 216 } |
217 | 217 |
218 const char* SkParse::FindScalars(const char str[], SkScalar value[], int count) | 218 const char* SkParse::FindScalars(const char str[], SkScalar value[], int count) |
219 { | 219 { |
220 SkASSERT(count >= 0); | 220 SkASSERT(count >= 0); |
221 | 221 |
222 if (count > 0) | 222 if (count > 0) |
223 { | 223 { |
224 for (;;) | 224 for (;;) |
225 { | 225 { |
226 str = SkParse::FindScalar(str, value); | 226 str = SkParse::FindScalar(str, value); |
227 if (--count == 0 || str == NULL) | 227 if (--count == 0 || str == nullptr) |
228 break; | 228 break; |
229 | 229 |
230 // keep going | 230 // keep going |
231 str = skip_sep(str); | 231 str = skip_sep(str); |
232 if (value) | 232 if (value) |
233 value += 1; | 233 value += 1; |
234 } | 234 } |
235 } | 235 } |
236 return str; | 236 return str; |
237 } | 237 } |
(...skipping 27 matching lines...) Expand all Loading... |
265 int SkParse::FindList(const char target[], const char list[]) | 265 int SkParse::FindList(const char target[], const char list[]) |
266 { | 266 { |
267 size_t len = strlen(target); | 267 size_t len = strlen(target); |
268 int index = 0; | 268 int index = 0; |
269 | 269 |
270 for (;;) | 270 for (;;) |
271 { | 271 { |
272 const char* end = strchr(list, ','); | 272 const char* end = strchr(list, ','); |
273 size_t entryLen; | 273 size_t entryLen; |
274 | 274 |
275 if (end == NULL) // last entry | 275 if (end == nullptr) // last entry |
276 entryLen = strlen(list); | 276 entryLen = strlen(list); |
277 else | 277 else |
278 entryLen = end - list; | 278 entryLen = end - list; |
279 | 279 |
280 if (entryLen == len && memcmp(target, list, len) == 0) | 280 if (entryLen == len && memcmp(target, list, len) == 0) |
281 return index; | 281 return index; |
282 if (end == NULL) | 282 if (end == nullptr) |
283 break; | 283 break; |
284 | 284 |
285 list = end + 1; // skip the ',' | 285 list = end + 1; // skip the ',' |
286 index += 1; | 286 index += 1; |
287 } | 287 } |
288 return -1; | 288 return -1; |
289 } | 289 } |
290 | 290 |
291 #ifdef SK_SUPPORT_UNITTEST | 291 #ifdef SK_SUPPORT_UNITTEST |
292 void SkParse::UnitTest() | 292 void SkParse::UnitTest() |
293 { | 293 { |
294 // !!! additional parse tests go here | 294 // !!! additional parse tests go here |
295 SkParse::TestColor(); | 295 SkParse::TestColor(); |
296 } | 296 } |
297 #endif | 297 #endif |
OLD | NEW |