From cfb02d4e78a8d9ce3f5d0845a1a05bd54e54bac3 Mon Sep 17 00:00:00 2001 From: "aa7133@att.com" Date: Thu, 2 Apr 2020 14:31:15 +0300 Subject: [PATCH] version 4.0.7 Bug in the way of the std:getline with '\n' reads files the value read in the config file fixed to avoid the imutable string in C++ behivior Change-Id: I3d2c0e38474425fd2eb6a4a7777dcec71e481db2 Signed-off-by: aa7133@att.com --- RIC-E2-TERMINATION/ReadConfigFile.h | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/RIC-E2-TERMINATION/ReadConfigFile.h b/RIC-E2-TERMINATION/ReadConfigFile.h index 9880eae..6f6f094 100644 --- a/RIC-E2-TERMINATION/ReadConfigFile.h +++ b/RIC-E2-TERMINATION/ReadConfigFile.h @@ -48,26 +48,21 @@ 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) { @@ -77,19 +72,20 @@ public: auto leftHand = line.find('='); if (leftHand == std::string::npos) { 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); if (value.length() == 0) { mdclog_write(MDCLOG_ERR, "problematic entry: %s no value ", line.c_str()); + line.clear(); continue; - } - trim(value); + 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()); } -- 2.16.6