i32 CCfgFile::_LoadUnicode(cch16* pFileData, cul32& ulDataSize) { //TCData< ch16 > Data; //Set ulDataSize / sizeof( ch16 ) because it must be size of the wide char buffer //ulDataSize is the size (in bytes) of all file data except BOM //Data.Create( (const xst_unknown)pFileData, ulDataSize, ulDataSize / sizeof( ch16 ), true ); //Tokenize file XST::StringUtil::TokensW vTokens; XST::StringUtil::SplitExcept( pFileData, &vTokens, L"\"", L"\"", L"\t\r\n= " ); //Get default section CSection* pCurrSection = xst_null; //_GetOrCreateSection( "" ); for(u32 i = 0; i < vTokens.size(); ++i) { xst_wstring& strCurrToken = vTokens[ i ]; //Skip comments if( strCurrToken[0] == L'#' || ( strCurrToken.length() > 1 && strCurrToken[0] == L'/' && strCurrToken[1] == L'/' ) ) continue; //If section name if( strCurrToken[0] == L'[' && strCurrToken[ strCurrToken.length() - 1 ] == L']' ) { //Create new section or add to the existing pCurrSection = _GetOrCreateSection( strCurrToken.substr( 1, strCurrToken.length() - 2 ) ); } else { //If key = value exists if( i + 1 < vTokens.size() ) { if( pCurrSection == xst_null ) { pCurrSection = _GetOrCreateSection( L"" ); } xst_wstring& strNextToken = vTokens[ i + 1 ]; ch16 c = strNextToken[ strNextToken.length() - 1 ]; if( strNextToken[0] == L'"' && strNextToken[ strNextToken.length() - 1 ] == L'"' ) { strNextToken = strNextToken.substr( 1, strNextToken.length() - 2 ); } pCurrSection->AddValue( strCurrToken, strNextToken ); ++i; } } } m_bLoaded = true; return RESULT::OK; }
i32 CCfgFile::_LoadAscii(cch8* pFileData, cul32& ulDataSize) { //Tokenize file XST::StringUtil::TokensA vTokens; XST::StringUtil::SplitExcept( pFileData, &vTokens, "\"", "\"", "\t\r\n= " ); //Get default section CSection* pCurrSection = xst_null; //_GetOrCreateSection( "" ); for(u32 i = 0; i < vTokens.size(); ++i) { xst_astring& strCurrToken = vTokens[ i ]; //Skip comments if( strCurrToken[0] == '#' || ( strCurrToken.length() > 1 && strCurrToken[0] == '/' && strCurrToken[1] == '/' ) ) continue; //If section name if( strCurrToken[0] == '[' && strCurrToken[ strCurrToken.length() - 1 ] == ']' ) { //Create new section or add to the existing pCurrSection = _GetOrCreateSection( strCurrToken.substr( 1, strCurrToken.length() - 2 ) ); } else { //If key = value exists if( i + 1 < vTokens.size() ) { if( pCurrSection == xst_null ) { pCurrSection = _GetOrCreateSection( "" ); } xst_astring& strNextToken = vTokens[ i + 1 ]; ch16 c = strNextToken[ strNextToken.length() - 1 ]; if( strNextToken[0] == '"' && strNextToken[ strNextToken.length() - 1 ] == '"' ) { strNextToken = strNextToken.substr( 1, strNextToken.length() - 2 ); } pCurrSection->AddValue( strCurrToken, strNextToken ); ++i; } } } m_bLoaded = true; return RESULT::OK; }