Update CCString.cpp

we can't change _string value after get Array.
This commit is contained in:
luocker 2013-12-27 00:26:02 +08:00
parent 2946fadcbd
commit fc655162fa
1 changed files with 6 additions and 6 deletions

View File

@ -181,20 +181,20 @@ void __String::appendWithFormat(const char* format, ...)
__Array* __String::componentsSeparatedByString(const char *delimiter) __Array* __String::componentsSeparatedByString(const char *delimiter)
{ {
__Array* result = __Array::create(); __Array* result = __Array::create();
std::string strTmp = _string;
size_t cutAt; size_t cutAt;
while( (cutAt = _string.find_first_of(delimiter)) != _string.npos ) while( (cutAt = strTmp.find_first_of(delimiter)) != strTmp.npos )
{ {
if(cutAt > 0) if(cutAt > 0)
{ {
result->addObject(__String::create(_string.substr(0, cutAt))); result->addObject(__String::create(strTmp.substr(0, cutAt)));
} }
_string = _string.substr(cutAt + 1); strTmp = strTmp.substr(cutAt + 1);
} }
if(_string.length() > 0) if(strTmp.length() > 0)
{ {
result->addObject(__String::create(_string)); result->addObject(__String::create(strTmp));
} }
return result; return result;