aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-09-24 20:06:03 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2009-09-24 20:06:03 +0000
commita8cf0aa53374337f2c133073db83c1c869b6501c (patch)
tree02c0bf0c6a4675d229addf5ae014ae247ff5b6b9
parentbb9aea999c29a45fcac3fdb9ecd4a45b65f603cb (diff)
use real strtof and snprintf to parse and dump floats
git-svn-id: http://skia.googlecode.com/svn/trunk@369 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/utils/SkParse.cpp16
-rw-r--r--src/utils/SkParsePath.cpp11
2 files changed, 20 insertions, 7 deletions
diff --git a/src/utils/SkParse.cpp b/src/utils/SkParse.cpp
index e7402801a6..df6691092b 100644
--- a/src/utils/SkParse.cpp
+++ b/src/utils/SkParse.cpp
@@ -206,11 +206,20 @@ const char* SkParse::FindMSec(const char str[], SkMSec* value)
return str;
}
-const char* SkParse::FindScalar(const char str[], SkScalar* value)
-{
+const char* SkParse::FindScalar(const char str[], SkScalar* value) {
SkASSERT(str);
str = skip_ws(str);
-
+#ifdef SK_SCALAR_IS_FLOAT
+ char* stop;
+ float v = ::strtof(str, &stop);
+ if (str == stop) {
+ return NULL;
+ }
+ if (value) {
+ *value = v;
+ }
+ return stop;
+#else
int sign = 0;
if (*str == '-')
{
@@ -251,6 +260,7 @@ const char* SkParse::FindScalar(const char str[], SkScalar* value)
n = (n ^ sign) - sign; // apply the sign
*value = SkFixedToScalar(n);
}
+#endif
return str;
}
diff --git a/src/utils/SkParsePath.cpp b/src/utils/SkParsePath.cpp
index df98436364..2e8921d03e 100644
--- a/src/utils/SkParsePath.cpp
+++ b/src/utils/SkParsePath.cpp
@@ -181,8 +181,14 @@ bool SkParsePath::FromSVGString(const char data[], SkPath* result) {
#include "SkStream.h"
static void write_scalar(SkWStream* stream, SkScalar value) {
+#ifdef SK_SCALAR_IS_FLOAT
+ char buffer[64];
+ int len = snprintf(buffer, sizeof(buffer), "%g", value);
+ char* stop = buffer + len;
+#else
char buffer[SkStrAppendScalar_MaxSize];
char* stop = SkStrAppendScalar(buffer, value);
+#endif
stream->write(buffer, stop - buffer);
}
@@ -191,10 +197,7 @@ static void append_scalars(SkWStream* stream, char verb, const SkScalar data[],
stream->write(&verb, 1);
write_scalar(stream, data[0]);
for (int i = 1; i < count; i++) {
- if (data[i] >= 0) {
- // can skip the separater if data[i] is negative
- stream->write(" ", 1);
- }
+ stream->write(" ", 1);
write_scalar(stream, data[i]);
}
}