// rdprofile.cpp // // A class to read an ini formatted configuration file. // // (C) Copyright 2002-2018 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU Library General Public License // version 2 as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // #include #include #include #include "rdprofile.h" RDProfileLine::RDProfileLine() { clear(); } QString RDProfileLine::tag() const { return line_tag; } void RDProfileLine::setTag(QString tag) { line_tag=tag; } QString RDProfileLine::value() const { return line_value; } void RDProfileLine::setValue(QString value) { line_value=value; } void RDProfileLine::clear() { line_tag=""; line_value=""; } RDProfileSection::RDProfileSection() { clear(); } QString RDProfileSection::name() const { return section_name; } void RDProfileSection::setName(QString name) { section_name=name; } bool RDProfileSection::getValue(QString tag,QString *value) const { for(unsigned i=0;iopen(QIODevice::ReadOnly)) { delete file; return false; } Q3TextStream *text=new Q3TextStream(file); QString line=text->readLine().stripWhiteSpace(); while(!line.isNull()) { if((line.left(1)!=";")&&(line.left(1)!="#")) { if((line.left(1)=="[")&&(line.right(1)=="]")) { section=line.mid(1,line.length()-2); profile_section.push_back(RDProfileSection()); profile_section.back().setName(section); } else if(((offset=line.find('='))!=-1)) { profile_section.back(). addValue(line.left(offset), line.right(line.length()-offset-1).stripWhiteSpace()); } } line=text->readLine().stripWhiteSpace(); } delete text; delete file; return true; } void RDProfile::setSourceString(const QString &str) { QStringList lines; QString section; int offset; profile_source=""; profile_section.resize(0); profile_section.push_back(RDProfileSection()); profile_section.back().setName(""); lines=str.split("\n"); for(int i=0;i