SkStringPrintf helper fucntion + a new unit test for it.

git-svn-id: http://skia.googlecode.com/svn/trunk@1766 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
tomhudson@google.com 2011-06-30 14:39:52 +00:00
parent b371ed1784
commit 3a1f6a06cc
3 changed files with 18 additions and 2 deletions

View File

@ -197,4 +197,7 @@ private:
uint16_t* fUCS2;
};
/// Creates a new string and writes into it using a printf()-style format.
SkString SkStringPrintf(const char* format, ...);
#endif

View File

@ -542,8 +542,6 @@ void SkString::prependf(const char format[], ...) {
this->prepend(buffer, strlen(buffer));
}
#undef VSNPRINTF
///////////////////////////////////////////////////////////////////////////////
void SkString::remove(size_t offset, size_t length) {
@ -605,3 +603,16 @@ SkAutoUCS2::SkAutoUCS2(const char utf8[]) {
SkAutoUCS2::~SkAutoUCS2() {
sk_free(fUCS2);
}
///////////////////////////////////////////////////////////////////////////////
SkString SkStringPrintf(const char* format, ...) {
SkString formattedOutput;
char buffer[kBufferSize];
ARGS_TO_BUFFER(format, buffer, kBufferSize);
formattedOutput.set(buffer);
return formattedOutput;
}
#undef VSNPRINTF

View File

@ -85,6 +85,8 @@ static void TestString(skiatest::Reporter* reporter) {
// SkDebugf(" received <%s> expected <%s>\n", a.c_str(), gRec[i].fString);
REPORTER_ASSERT(reporter, a.equals(gRec[i].fString));
}
REPORTER_ASSERT(reporter, SkStringPrintf("%i", 0).equals("0"));
}
#include "TestClassDef.h"