mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3146 from tks2shimizu/develop
closed 2408: Add componentsSeparatedByString function for String class.
This commit is contained in:
commit
2ed5a40a36
|
@ -3,6 +3,7 @@
|
||||||
#include "ccMacros.h"
|
#include "ccMacros.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "CCArray.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -151,6 +152,28 @@ void String::appendWithFormat(const char* format, ...)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Array* String::componentsSeparatedByString(const char *delimiter)
|
||||||
|
{
|
||||||
|
Array* result = Array::create();
|
||||||
|
|
||||||
|
int cutAt;
|
||||||
|
while( (cutAt = _string.find_first_of(delimiter)) != _string.npos )
|
||||||
|
{
|
||||||
|
if(cutAt > 0)
|
||||||
|
{
|
||||||
|
result->addObject(String::create(_string.substr(0, cutAt)));
|
||||||
|
}
|
||||||
|
_string = _string.substr(cutAt + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_string.length() > 0)
|
||||||
|
{
|
||||||
|
result->addObject(String::create(_string));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool String::isEqual(const Object* pObject)
|
bool String::isEqual(const Object* pObject)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
|
|
|
@ -86,6 +86,9 @@ public:
|
||||||
/** append(w/ format) additional characters at the end of its current value */
|
/** append(w/ format) additional characters at the end of its current value */
|
||||||
void appendWithFormat(const char* format, ...);
|
void appendWithFormat(const char* format, ...);
|
||||||
|
|
||||||
|
/** split a string */
|
||||||
|
Array* componentsSeparatedByString(const char *delimiter);
|
||||||
|
|
||||||
/* override functions */
|
/* override functions */
|
||||||
virtual bool isEqual(const Object* pObject);
|
virtual bool isEqual(const Object* pObject);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue