Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: src/utils/SkParse.cpp

Issue 117053002: remove SK_SCALAR_IS_[FLOAT,FIXED] and assume floats (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 while (--remaining10s >= 0) 194 while (--remaining10s >= 0)
195 n *= 10; 195 n *= 10;
196 if (value) 196 if (value)
197 *value = (n ^ sign) - sign; 197 *value = (n ^ sign) - sign;
198 return str; 198 return str;
199 } 199 }
200 200
201 const char* SkParse::FindScalar(const char str[], SkScalar* value) { 201 const char* SkParse::FindScalar(const char str[], SkScalar* value) {
202 SkASSERT(str); 202 SkASSERT(str);
203 str = skip_ws(str); 203 str = skip_ws(str);
204 #ifdef SK_SCALAR_IS_FLOAT 204
205 char* stop; 205 char* stop;
206 float v = (float)strtod(str, &stop); 206 float v = (float)strtod(str, &stop);
207 if (str == stop) { 207 if (str == stop) {
208 return NULL; 208 return NULL;
209 } 209 }
210 if (value) { 210 if (value) {
211 *value = v; 211 *value = v;
212 } 212 }
213 return stop; 213 return stop;
214 #else
215 int sign = 0;
216 if (*str == '-')
217 {
218 sign = -1;
219 str += 1;
220 }
221
222 if (!is_digit(*str) && *str != '.')
223 return NULL;
224
225 int n = 0;
226 while (is_digit(*str))
227 {
228 n = 10*n + *str - '0';
229 if (n > 0x7FFF)
230 return NULL;
231 str += 1;
232 }
233 n <<= 16;
234
235 if (*str == '.')
236 {
237 static const int gFractions[] = { (1 << 24) / 10, (1 << 24) / 100, (1 << 24) / 1000,
238 (1 << 24) / 10000, (1 << 24) / 100000 };
239 str += 1;
240 int d = 0;
241 const int* fraction = gFractions;
242 const int* end = &fraction[SK_ARRAY_COUNT(gFractions)];
243 while (is_digit(*str) && fraction < end)
244 d += (*str++ - '0') * *fraction++;
245 d += 0x80; // round
246 n += d >> 8;
247 }
248 while (is_digit(*str))
249 str += 1;
250 if (value)
251 {
252 n = (n ^ sign) - sign; // apply the sign
253 *value = SkFixedToScalar(n);
254 }
255 #endif
256 return str;
257 } 214 }
258 215
259 const char* SkParse::FindScalars(const char str[], SkScalar value[], int count) 216 const char* SkParse::FindScalars(const char str[], SkScalar value[], int count)
260 { 217 {
261 SkASSERT(count >= 0); 218 SkASSERT(count >= 0);
262 219
263 if (count > 0) 220 if (count > 0)
264 { 221 {
265 for (;;) 222 for (;;)
266 { 223 {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 return -1; 286 return -1;
330 } 287 }
331 288
332 #ifdef SK_SUPPORT_UNITTEST 289 #ifdef SK_SUPPORT_UNITTEST
333 void SkParse::UnitTest() 290 void SkParse::UnitTest()
334 { 291 {
335 // !!! additional parse tests go here 292 // !!! additional parse tests go here
336 SkParse::TestColor(); 293 SkParse::TestColor();
337 } 294 }
338 #endif 295 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698