// implement the functions CCRect CCRectFromString ( const KDchar* szContent ) { CCRect tRet = CCRectZero; do { CC_BREAK_IF ( !szContent ); std::string sContent = szContent; // find the first '{' and the third '}' KDuint nPosLeft = sContent.find ( '{' ); KDuint nPosRight = sContent.find ( '}' ); for ( KDint i = 1; i < 3; ++i ) { if ( nPosRight == std::string::npos ) { break; } nPosRight = sContent.find ( '}', nPosRight + 1 ); } CC_BREAK_IF ( nPosLeft == std::string::npos || nPosRight == std::string::npos ); sContent = sContent.substr ( nPosLeft + 1, nPosRight - nPosLeft - 1 ); KDuint nPointEnd = sContent.find ( '}' ); CC_BREAK_IF ( nPointEnd == std::string::npos ); nPointEnd = sContent.find ( ',', nPointEnd ); CC_BREAK_IF ( nPointEnd == std::string::npos ); // get the point string and size string std::string sPointStr = sContent.substr ( 0, nPointEnd ); std::string sSizeStr = sContent.substr ( nPointEnd + 1, sContent.length ( ) - nPointEnd ); // split the string with ',' strArray vPointInfo; CC_BREAK_IF ( !splitWithForm ( sPointStr.c_str ( ), vPointInfo ) ); strArray vSizeInfo; CC_BREAK_IF ( !splitWithForm ( sSizeStr.c_str ( ), vSizeInfo ) ); tRet = CCRectMake ( kdStrtodKHR ( vPointInfo [ 0 ].c_str ( ), KD_NULL ), kdStrtodKHR ( vPointInfo [ 1 ].c_str ( ), KD_NULL ), kdStrtodKHR ( vSizeInfo [ 0 ].c_str ( ), KD_NULL ), kdStrtodKHR ( vSizeInfo [ 1 ].c_str ( ), KD_NULL )); } while ( 0 ); return tRet; }
CCRect CCRectFromString(const char* pszContent) { CCRect result = CCRectZero; do { CC_BREAK_IF(!pszContent); std::string content = pszContent; // find the first '{' and the third '}' int nPosLeft = content.find('{'); int nPosRight = content.find('}'); for (int i = 1; i < 3; ++i) { if (nPosRight == (int)std::string::npos) { break; } nPosRight = content.find('}', nPosRight + 1); } CC_BREAK_IF(nPosLeft == (int)std::string::npos || nPosRight == (int)std::string::npos); content = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1); int nPointEnd = content.find('}'); CC_BREAK_IF(nPointEnd == (int)std::string::npos); nPointEnd = content.find(',', nPointEnd); CC_BREAK_IF(nPointEnd == (int)std::string::npos); // get the point string and size string std::string pointStr = content.substr(0, nPointEnd); std::string sizeStr = content.substr(nPointEnd + 1, content.length() - nPointEnd); // split the string with ',' strArray pointInfo; CC_BREAK_IF(!splitWithForm(pointStr.c_str(), pointInfo)); strArray sizeInfo; CC_BREAK_IF(!splitWithForm(sizeStr.c_str(), sizeInfo)); float x = (float) atof(pointInfo[0].c_str()); float y = (float) atof(pointInfo[1].c_str()); float width = (float) atof(sizeInfo[0].c_str()); float height = (float) atof(sizeInfo[1].c_str()); result = CCRectMake(x, y, width, height); } while (0); return result; }
cocos2d::Color3B Color3BFromString(const char* pszContent) { std::vector<std::string> strs; if(!splitWithForm(pszContent, strs)) return cocos2d::ccBLACK; int r = (int) atoi(strs[0].c_str()); int g = (int) atoi(strs[1].c_str()); int b = (int) atoi(strs[2].c_str()); return cocos2d::Color3B(r,g,b); }
CCSize CCSizeFromString ( const KDchar* szContent ) { strArray vStrings; if ( splitWithForm ( szContent, vStrings ) ) { return CCSizeMake ( kdStrtodKHR ( vStrings [ 0 ].c_str ( ), KD_NULL ) , kdStrtodKHR ( vStrings [ 1 ].c_str ( ), KD_NULL ) ); } else { return CCSizeZero; } }
CCSize CCSizeFromString(const char* pszContent) { CCSize ret = CCSizeZero; do { strArray strs; CC_BREAK_IF(!splitWithForm(pszContent, strs)); float width = (float) atof(strs[0].c_str()); float height = (float) atof(strs[1].c_str()); ret = CCSizeMake(width, height); } while (0); return ret; }
CCPoint CCPointFromString(const char* pszContent) { CCPoint ret = CCPointZero; do { strArray strs; CC_BREAK_IF(!splitWithForm(pszContent, strs)); float x = (float) atof(strs[0].c_str()); float y = (float) atof(strs[1].c_str()); ret = CCPointMake(x, y); } while (0); return ret; }