From eca7db6a503434a1fc2e6f78d1b0fc4f8f6a57c2 Mon Sep 17 00:00:00 2001 From: Tomoaki Shimizu Date: Wed, 10 Jul 2013 10:50:13 +0900 Subject: [PATCH] Add append function for String class. The append function is useful when adding a string. So, I added it to String class. --- cocos2dx/cocoa/CCString.cpp | 22 ++++++++++++++++++++++ cocos2dx/cocoa/CCString.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/cocos2dx/cocoa/CCString.cpp b/cocos2dx/cocoa/CCString.cpp index 74faf7a180..3305372e4c 100644 --- a/cocos2dx/cocoa/CCString.cpp +++ b/cocos2dx/cocoa/CCString.cpp @@ -129,6 +129,28 @@ int String::compare(const char * pStr) const return strcmp(getCString(), pStr); } +void String::append(const std::string& str) +{ + _string.append(str); +} + +void String::appendWithFormat(const char* format, ...) +{ + va_list ap; + va_start(ap, format); + + char* pBuf = (char*)malloc(kMaxStringLen); + if (pBuf != NULL) + { + vsnprintf(pBuf, kMaxStringLen, format, ap); + _string.append(pBuf); + free(pBuf); + } + + va_end(ap); + +} + bool String::isEqual(const Object* pObject) { bool bRet = false; diff --git a/cocos2dx/cocoa/CCString.h b/cocos2dx/cocoa/CCString.h index bd17c9b43b..59f4225dae 100644 --- a/cocos2dx/cocoa/CCString.h +++ b/cocos2dx/cocoa/CCString.h @@ -80,6 +80,12 @@ public: /** compare to a c string */ int compare(const char *) const; + /** append additional characters at the end of its current value */ + void append(const std::string& str); + + /** append(w/ format) additional characters at the end of its current value */ + void appendWithFormat(const char* format, ...); + /* override functions */ virtual bool isEqual(const Object* pObject);