X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=RIC-E2-TERMINATION%2FReadConfigFile.h;h=87e511d00e7f4f6c2b96f6825ee99bbab3894f57;hb=b222eac2063d47ddcd24fdb380028379c5d8c34d;hp=469d5efcdd764e3f7a7301b88db155aae475a37d;hpb=3bac2da3306cb753f967ce41dad1e7719380c916;p=ric-plt%2Fe2.git diff --git a/RIC-E2-TERMINATION/ReadConfigFile.h b/RIC-E2-TERMINATION/ReadConfigFile.h index 469d5ef..87e511d 100644 --- a/RIC-E2-TERMINATION/ReadConfigFile.h +++ b/RIC-E2-TERMINATION/ReadConfigFile.h @@ -48,45 +48,47 @@ public: std::string line; std::string section; - while (std::getline(file,line)) { + while (std::getline(file,line, '\n')) { if (!line.length() || line[0] == '#' || line[0] == ';' || line[0] == '{') { + line.clear(); continue; } -// else if (line[0] == '#') { -// continue; -// } else if (line[0] == ';') { -// continue; -// } - - if (line[0] =='[') { //section auto sectionEnd = line.find(']'); if (sectionEnd == std::string::npos) { mdclog_write(MDCLOG_ERR, "Error section definition: %s ", line.c_str()); section.clear(); return -1; -// continue; } section = line.substr(1, sectionEnd - 1) + "."; + section = trim(section); + line.clear(); continue; } + if (mdclog_level_get() >= MDCLOG_INFO) { + mdclog_write(MDCLOG_INFO, "line = %s ", line.c_str()); + } auto leftHand = line.find('='); if (leftHand == std::string::npos) { - mdclog_write(MDCLOG_ERR, "problematic entry: %s ", line.c_str()); + mdclog_write(MDCLOG_ERR, "problematic entry: %s no equal sign", line.c_str()); + line.clear(); continue; } -// auto name = line.substr(0,leftHand); -// trim(name); auto name = section + trim(line.substr(0, leftHand)); - auto value = line.substr(leftHand+1); + auto value = line.substr(leftHand + 1); if (value.length() == 0) { mdclog_write(MDCLOG_ERR, "problematic entry: %s no value ", line.c_str()); + line.clear(); continue; + } + line.clear(); + value = trim(value); + if (mdclog_level_get() >= MDCLOG_INFO) { + mdclog_write(MDCLOG_INFO, "entry = %s value = %s", name.c_str(), value.c_str()); } - trim(value); //cout << "entry = " << name << " value = " << value << endl; entries[name] = value; } @@ -146,7 +148,7 @@ private: return str; } - inline static std::string& trim(basic_string str, const std::string& chars = "\t\n\v\f\r ") { + inline static std::string& trim(std::string str, const std::string& chars = "\t\n\v\f\r ") { return ltrim(rtrim(str, chars), chars); } };