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:
parent
759876a922
commit
677cbedda7
@ -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
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user