From: Maxim Mamontov Date: Fri, 10 Dec 2010 14:41:39 +0000 (+0200) Subject: Мелкие правки в реализации CONFIGFILE X-Git-Tag: 2.407-rc3~285 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/b12381fd076b83ab289dc38a14b701c4fbb76715 Мелкие правки в реализации CONFIGFILE --- diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index 9c8c46e8..47a92db0 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -45,32 +45,23 @@ bool StringCaseCmp(const string & str1, const string & str2) return (strcasecmp(str1.c_str(), str2.c_str()) < 0); } //--------------------------------------------------------------------------- -CONFIGFILE::CONFIGFILE(const string & fn) +CONFIGFILE::CONFIGFILE(const string & fn, bool nook) : param_val(StringCaseCmp), fileName(fn), error(0) { ifstream f(fileName.c_str()); -//FILE * f = fopen(fileName.c_str(), "rt"); if (!f) { - error = -1; + if (!nook) + error = -1; return; } string line; while (getline(f, line)) { - /*unsigned char c = fgetc(f); - while (!feof(f)) - { - if (c == '\n') - break; - line.push_back(c); - c = fgetc(f); - }*/ - size_t pos = line.find('#'); if (pos != string::npos) line.resize(pos); @@ -78,20 +69,6 @@ while (getline(f, line)) if (line.find_first_not_of(" \t\r") == string::npos) continue; - /*bool emptyLine = true; - for (unsigned int i = 0; i < line.size(); i++) - { - if (line[i] != ' ' && line[i] != '\t' && line[i] != '\n' && line[i] != '\r') - { - emptyLine = false; - break; - } - } - if (emptyLine) - { - continue; - }*/ - pos = line.find_first_of('='); if (pos == string::npos) { @@ -133,7 +110,7 @@ if (!f.is_open()) map::const_iterator it = param_val.begin(); while (it != param_val.end()) { - f << it->first << "=" << it->second << endl; + f << it->first << "=" << it->second << "\n"; it++; } diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/conffiles.h index d912d9ab..943fd4c8 100644 --- a/stglibs/conffiles.lib/conffiles.h +++ b/stglibs/conffiles.lib/conffiles.h @@ -45,7 +45,7 @@ typedef bool (*StringCaseCmp_t)(const string & str1, const string & str2); class CONFIGFILE { public: - CONFIGFILE(const string & fn); + CONFIGFILE(const string & fn, bool nook = false); ~CONFIGFILE(); const string & GetFileName() const; @@ -64,7 +64,7 @@ public: int ReadULongLongInt(const string & param, uint64_t *, uint64_t) const; int ReadDouble(const string & param, double * val, double defaultVal) const; - //int WriteString(const string & param, const char * val); + int WriteString(const string & param, const char * val) { return WriteString(param, std::string(val)); } int WriteString(const string & param, const string & val); int WriteInt(const string & param, int64_t val); int WriteDouble(const string & param, double val);