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

Unified Diff: src/core/SkString.cpp

Issue 17448012: Add SkString::appendU32() and SkString::appendU64() (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: add_cornercase_test_that_works_now Created 7 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkString.h ('k') | tests/StringTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkString.cpp
===================================================================
--- src/core/SkString.cpp (revision 9684)
+++ src/core/SkString.cpp (working copy)
@@ -68,48 +68,40 @@
return -1;
}
-char* SkStrAppendS32(char string[], int32_t dec) {
+char* SkStrAppendU32(char string[], uint32_t dec) {
SkDEBUGCODE(char* start = string;)
- char buffer[SkStrAppendS32_MaxSize];
+ char buffer[SkStrAppendU32_MaxSize];
char* p = buffer + sizeof(buffer);
- bool neg = false;
- if (dec < 0) {
- neg = true;
- dec = -dec;
- }
-
do {
*--p = SkToU8('0' + dec % 10);
dec /= 10;
} while (dec != 0);
- if (neg) {
- *--p = '-';
- }
-
SkASSERT(p >= buffer);
char* stop = buffer + sizeof(buffer);
while (p < stop) {
*string++ = *p++;
}
- SkASSERT(string - start <= SkStrAppendS32_MaxSize);
+ SkASSERT(string - start <= SkStrAppendU32_MaxSize);
return string;
}
-char* SkStrAppendS64(char string[], int64_t dec, int minDigits) {
+char* SkStrAppendS32(char string[], int32_t dec) {
+ if (dec < 0) {
+ *string++ = '-';
+ dec = -dec;
+ }
+ return SkStrAppendU32(string, static_cast<uint32_t>(dec));
+}
+
+char* SkStrAppendU64(char string[], uint64_t dec, int minDigits) {
SkDEBUGCODE(char* start = string;)
- char buffer[SkStrAppendS64_MaxSize];
+ char buffer[SkStrAppendU64_MaxSize];
char* p = buffer + sizeof(buffer);
- bool neg = false;
- if (dec < 0) {
- neg = true;
- dec = -dec;
- }
-
do {
*--p = SkToU8('0' + (int32_t) (dec % 10));
dec /= 10;
@@ -121,18 +113,23 @@
minDigits--;
}
- if (neg) {
- *--p = '-';
- }
SkASSERT(p >= buffer);
size_t cp_len = buffer + sizeof(buffer) - p;
memcpy(string, p, cp_len);
string += cp_len;
- SkASSERT(string - start <= SkStrAppendS64_MaxSize);
+ SkASSERT(string - start <= SkStrAppendU64_MaxSize);
return string;
}
+char* SkStrAppendS64(char string[], int64_t dec, int minDigits) {
+ if (dec < 0) {
+ *string++ = '-';
+ dec = -dec;
+ }
+ return SkStrAppendU64(string, static_cast<uint64_t>(dec), minDigits);
+}
+
char* SkStrAppendFloat(char string[], float value) {
// since floats have at most 8 significant digits, we limit our %g to that.
static const char gFormat[] = "%.8g";
@@ -518,6 +515,18 @@
this->insert(offset, buffer, stop - buffer);
}
+void SkString::insertU32(size_t offset, uint32_t dec) {
+ char buffer[SkStrAppendU32_MaxSize];
+ char* stop = SkStrAppendU32(buffer, dec);
+ this->insert(offset, buffer, stop - buffer);
+}
+
+void SkString::insertU64(size_t offset, uint64_t dec, int minDigits) {
+ char buffer[SkStrAppendU64_MaxSize];
+ char* stop = SkStrAppendU64(buffer, dec, minDigits);
+ this->insert(offset, buffer, stop - buffer);
+}
+
void SkString::insertHex(size_t offset, uint32_t hex, int minDigits) {
minDigits = SkPin32(minDigits, 0, 8);
« no previous file with comments | « include/core/SkString.h ('k') | tests/StringTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698