diff options
-rw-r--r-- | include/core/SkString.h | 11 | ||||
-rw-r--r-- | src/core/SkString.cpp | 15 |
2 files changed, 18 insertions, 8 deletions
diff --git a/include/core/SkString.h b/include/core/SkString.h index 5b41a78588..ba9de02d65 100644 --- a/include/core/SkString.h +++ b/include/core/SkString.h @@ -44,7 +44,16 @@ char* SkStrAppendS64(char buffer[], int64_t, int minDigits); * Thus if the caller wants to add a 0 at the end, buffer must be at least * SkStrAppendScalar_MaxSize + 1 bytes large. */ -char* SkStrAppendScalar(char buffer[], SkScalar); +#ifdef SK_SCALAR_IS_FLOAT + #define SkStrAppendScalar SkStrAppendFloat +#else + #define SkStrAppendScalar SkStrAppendFixed +#endif + +#ifdef SK_CAN_USE_FLOAT +char* SkStrAppendFloat(char buffer[], float); +#endif +char* SkStrAppendFixed(char buffer[], SkFixed); /** \class SkString diff --git a/src/core/SkString.cpp b/src/core/SkString.cpp index ca97e0b592..b8f99c7c88 100644 --- a/src/core/SkString.cpp +++ b/src/core/SkString.cpp @@ -134,21 +134,23 @@ char* SkStrAppendS64(char string[], int64_t dec, int minDigits) return string; } -char* SkStrAppendScalar(char string[], SkScalar value) +#ifdef SK_CAN_USE_FLOAT +char* SkStrAppendFloat(char string[], float value) { - SkDEBUGCODE(char* start = string;) - -#ifdef SK_SCALAR_IS_FLOAT // since floats have at most 8 significant digits, we limit our %g to that. static const char gFormat[] = "%.8g"; // make it 1 larger for the terminating 0 char buffer[SkStrAppendScalar_MaxSize + 1]; int len = SNPRINTF(buffer, sizeof(buffer), gFormat, value); memcpy(string, buffer, len); + SkASSERT(len <= SkStrAppendScalar_MaxSize); return string + len; -#else - SkFixed x = SkScalarToFixed(value); +} +#endif +char* SkStrAppendFixed(char string[], SkFixed x) +{ + SkDEBUGCODE(char* start = string;) if (x < 0) { *string++ = '-'; @@ -182,7 +184,6 @@ char* SkStrAppendScalar(char string[], SkScalar value) x %= powerOfTen; } while (x != 0); } -#endif SkASSERT(string - start <= SkStrAppendScalar_MaxSize); return string; |