From 32d2752a265a17f1c39d85b3d7e7e34bff645818 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Sun, 28 Apr 2024 13:20:39 +0530 Subject: [PATCH] SimpCfg:Make str_trim flexible, use to trim , wrt value Now one can pass the list/string of chars to trim at either end. --- common/simpcfg.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/common/simpcfg.hpp b/common/simpcfg.hpp index ff68f85ce89c8a..287662eae561ad 100644 --- a/common/simpcfg.hpp +++ b/common/simpcfg.hpp @@ -44,9 +44,9 @@ bool sc_get_bool(std::string &group, std::string &key) { return gm[key]; } -std::string str_trim(std::string sin) { - sin.erase(sin.find_last_not_of(" \t\n")+1); - sin.erase(0, sin.find_first_not_of(" \t\n")); +std::string str_trim(std::string sin, std::string trimChars=" \t\n") { + sin.erase(sin.find_last_not_of(trimChars)+1); + sin.erase(0, sin.find_first_not_of(trimChars)); return sin; } @@ -91,12 +91,15 @@ void sc_load(std::string &fname) { key = str_trim(key); std::string value = curL.substr(dPos+1); value = str_trim(value); - LOG_TEELN("DBUG:%s:kv:%s:%s:%s", __func__, group.c_str(), key.c_str(), value.c_str()); + value = str_trim(value, ","); + std::string vtype = "bool"; if ((value == "true") || (value == "false")) { sc_set_bool(group, key, value == "true" ? true : false); } else { + vtype = "string"; sc_set_string(group, key, value); } + LOG_TEELN("DBUG:%s:kv:%s:%s:%s:%s", __func__, group.c_str(), key.c_str(), vtype.c_str(), value.c_str()); } }