From 000245b8e8779e7adb27d462448a8a16a3881f1b Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Mon, 29 Apr 2024 00:00:11 +0530 Subject: [PATCH] SimpCfg:Warn possible nonstring strings, some invalid floats Warn if something not starting with double quote is being treated as a string. Show some examples of invalid floating point values wrt this logics floating point determination code --- common/simpcfg.hpp | 15 +++++++++------ examples/chaton_meta.simpcfg | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/common/simpcfg.hpp b/common/simpcfg.hpp index 7346087bb..33623312e 100644 --- a/common/simpcfg.hpp +++ b/common/simpcfg.hpp @@ -137,10 +137,10 @@ public: void load(const std::string &fname) { std::ifstream f {fname}; if (!f) { - LERRR_LN("ERRR:%s:%s:failed to load...", __func__, fname.c_str()); + LERRR_LN("ERRR:SC:%s:%s:failed to load...", __func__, fname.c_str()); throw std::runtime_error { "ERRR:SimpCfg:File not found" }; } else { - LDBUG_LN("DBUG:%s:%s", __func__, fname.c_str()); + LDBUG_LN("DBUG:SC:%s:%s", __func__, fname.c_str()); } std::string group; int iLine = 0; @@ -159,17 +159,17 @@ public: if (bGroup) { curL = str_trim_single(curL, "\""); group = curL; - LDBUG_LN("DBUG:%s:group:%s", __func__, group.c_str()); + LDBUG_LN("DBUG:SC:%s:group:%s", __func__, group.c_str()); continue; } auto dPos = curL.find(':'); if (dPos == std::string::npos) { - LERRR_LN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str()); + LERRR_LN("ERRR:SC:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str()); throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" }; } auto dEnd = curL.length() - dPos; if ((dPos == 0) || (dEnd < 2)) { - LERRR_LN("ERRR:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str()); + LERRR_LN("ERRR:SC:%s:%d:invalid key value line:%s", __func__, iLine, curL.c_str()); throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" }; } std::string key = curL.substr(0, dPos); @@ -189,10 +189,13 @@ public: set_double(group, key, value); } else { vtype = "string"; + if (!value.empty() && (value.front() != '"')) { + LWARN_LN("WARN:SC:%s:kv:is this string:%s", __func__, value.c_str()); + } value = str_trim_single(value, "\""); set_string(group, key, value); } - //LDBUG_LN("DBUG:%s:kv:%s:%s:%s:%s", __func__, group.c_str(), key.c_str(), vtype.c_str(), value.c_str()); + //LDBUG_LN("DBUG:SC:%s:kv:%s:%s:%s:%s", __func__, group.c_str(), key.c_str(), vtype.c_str(), value.c_str()); } } diff --git a/examples/chaton_meta.simpcfg b/examples/chaton_meta.simpcfg index c8c0cb49b..283cc238e 100644 --- a/examples/chaton_meta.simpcfg +++ b/examples/chaton_meta.simpcfg @@ -226,8 +226,14 @@ "testme" "int": 1234 "sint": -9876543210 + "another int": 0xff "float": 12.34 "double1": +12.0e-123 "double2": -12.0e-123678 "double3": -12.0e300 + "isit double1": -12.e300 + "isit double2": -12. + "yes double2": -12.0 + "isit double3": .0123 + "yes double3": 0.0123