//==================================================================================== int IniFile::extractSection(const AnsiStr& title, std::vector<AnsiStr>& lines) { lines.resize(0); AnsiStr str; AnsiStr titleUpperCased = title; titleUpperCased.toUpper(); int idxStart = -1; for(int i=0; i < (int)m_content.size(); i++) { str = m_content[i]; if((str.firstChar() == '[')&&(str.lastChar() == ']')) { //[ + ] = 2 str = str.substr(1, str.length() - 2); if(str.toUpper() == titleUpperCased) { idxStart = i; break; } } } //Process Content for(int i=idxStart+1; i < (int)m_content.size(); i++) { str = m_content[i]; if((str.firstChar() == '[')&&(str.lastChar() == ']')) break; else lines.push_back(str); } return (int)lines.size(); }
bool IniFile::readIntArrayU32(const AnsiStr& section, const AnsiStr& variable, int ctExpected, std::vector<U32>& arrayInt) { AnsiStr strVal; if(readValue(section, variable, strVal)) { int pos; int iComp = 0; AnsiStr strTemp; if(strVal.firstChar() == '(') strVal = strVal.substr(1); else return false; while(strVal.lfind(',', pos)) { strTemp = strVal.substr(0, pos); strVal = strVal.substr(pos + 1); strVal.removeStartEndSpaces(); arrayInt.push_back(atoi(strTemp.ptr())); iComp++; } if(strVal.length() >= 1) { if(strVal.lastChar() == ')') { strTemp = strVal.substr(0, strVal.length() - 1); strTemp.removeStartEndSpaces(); if(strTemp.length() > 0) arrayInt.push_back(atoi(strTemp.ptr())); } } } return ((int)arrayInt.size() == ctExpected); }
//==================================================================================== bool IniFile::readLine(const AnsiStr& section, const AnsiStr& variable, AnsiStr& strLine) { int startPos = hasSection(section); if(startPos < 0) return false; //Record file pos for(int i=startPos+1; i < (int)m_content.size(); i++) { strLine = m_content[i]; //If it is a comment then ignore if(strLine.firstChar() == '#') continue; //Is section? if((strLine.firstChar() == L'[')&&(strLine.lastChar() == L']')) { return false; } else { for(int iChar=0; iChar < strLine.length(); iChar++) { if(strLine[iChar] == L'=') { AnsiStr str = strLine.substr(0, iChar); AnsiStr varUpperCased = variable; varUpperCased.toUpper(); if( str.toUpper() == varUpperCased ) { return true; } else break; } } } } return false; }
//==================================================================================== int IniFile::hasSection(const AnsiStr& strSection) { AnsiStr str; for(int i=0; i < (int)m_content.size(); i++) { str = m_content[i]; char ch = str.firstChar(); ch = str.lastChar(); if((str.firstChar() == '[')&&(str.lastChar() == ']')) { //[ + ] = 2 str = str.substr(1, str.length() - 2); AnsiStr strSecUpperCased = strSection; strSecUpperCased.toUpper(); if(str.toUpper() == strSecUpperCased) return i; } } return -1; }
//==================================================================================== vec4f IniFile::readVec4f(const AnsiStr& section, const AnsiStr& variable) { AnsiStr strVal; vec4f res; if(readValue(section, variable, strVal)) { float f[4]; int pos; int iComp = 0; AnsiStr strTemp; if(strVal.firstChar() == '(') strVal = strVal.substr(1); else return res; while(strVal.lfind(',', pos)) { strTemp = strVal.substr(0, pos); strVal = strVal.substr(pos + 1); strVal.removeStartEndSpaces(); f[iComp] = static_cast<float>(atof(strTemp.ptr())); iComp++; } if(strVal.length() >= 1 && iComp < 4) { if(strVal.lastChar() == ')') { strTemp = strVal.substr(0, strVal.length() - 1); strTemp.removeStartEndSpaces(); f[iComp] = static_cast<float>(atof(strTemp.ptr())); } } res = vec4f(f[0], f[1], f[2], f[3]); } return res; }