Ejemplo n.º 1
0
// 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;
}
Ejemplo n.º 2
0
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;
    }
}
Ejemplo n.º 3
0
KDint KD_APIENTRY kdMain(KDint argc, const KDchar *const *argv)
{
    static const KDsize n = 1024 * 1000;

    for(KDsize i = 1; i < n; i = i + 1024)
    {
        KDchar buf[512];
        kdSnprintfKHR(buf, sizeof(buf), "%zu.%zu", i, i + 1);

        KDfloat32 f = kdStrtof(buf, KD_NULL);
        TEST_EXPR(f > 0.0);

        KDfloat64KHR d = kdStrtodKHR(buf, KD_NULL);
        TEST_EXPR(d > 0.0);
    }

    return 0;
}