Expose explicit functions to stringify float's and fixed's.

See http://codereview.appspot.com/4240050/

Review URL: http://codereview.appspot.com/4240068

git-svn-id: http://skia.googlecode.com/svn/trunk@880 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
vandebo@chromium.org 2011-03-03 18:20:12 +00:00
parent 759876a922
commit 677cbedda7
2 changed files with 18 additions and 8 deletions

View File

@ -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

View File

@ -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;