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
This commit is contained in:
parent
a6648b02f2
commit
000245b8e8
2 changed files with 15 additions and 6 deletions
|
@ -137,10 +137,10 @@ public:
|
||||||
void load(const std::string &fname) {
|
void load(const std::string &fname) {
|
||||||
std::ifstream f {fname};
|
std::ifstream f {fname};
|
||||||
if (!f) {
|
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" };
|
throw std::runtime_error { "ERRR:SimpCfg:File not found" };
|
||||||
} else {
|
} else {
|
||||||
LDBUG_LN("DBUG:%s:%s", __func__, fname.c_str());
|
LDBUG_LN("DBUG:SC:%s:%s", __func__, fname.c_str());
|
||||||
}
|
}
|
||||||
std::string group;
|
std::string group;
|
||||||
int iLine = 0;
|
int iLine = 0;
|
||||||
|
@ -159,17 +159,17 @@ public:
|
||||||
if (bGroup) {
|
if (bGroup) {
|
||||||
curL = str_trim_single(curL, "\"");
|
curL = str_trim_single(curL, "\"");
|
||||||
group = 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;
|
continue;
|
||||||
}
|
}
|
||||||
auto dPos = curL.find(':');
|
auto dPos = curL.find(':');
|
||||||
if (dPos == std::string::npos) {
|
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" };
|
throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" };
|
||||||
}
|
}
|
||||||
auto dEnd = curL.length() - dPos;
|
auto dEnd = curL.length() - dPos;
|
||||||
if ((dPos == 0) || (dEnd < 2)) {
|
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" };
|
throw std::runtime_error { "ERRR:SimpCfg:Invalid key value line" };
|
||||||
}
|
}
|
||||||
std::string key = curL.substr(0, dPos);
|
std::string key = curL.substr(0, dPos);
|
||||||
|
@ -189,10 +189,13 @@ public:
|
||||||
set_double(group, key, value);
|
set_double(group, key, value);
|
||||||
} else {
|
} else {
|
||||||
vtype = "string";
|
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, "\"");
|
value = str_trim_single(value, "\"");
|
||||||
set_string(group, key, 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,8 +226,14 @@
|
||||||
"testme"
|
"testme"
|
||||||
"int": 1234
|
"int": 1234
|
||||||
"sint": -9876543210
|
"sint": -9876543210
|
||||||
|
"another int": 0xff
|
||||||
"float": 12.34
|
"float": 12.34
|
||||||
"double1": +12.0e-123
|
"double1": +12.0e-123
|
||||||
"double2": -12.0e-123678
|
"double2": -12.0e-123678
|
||||||
"double3": -12.0e300
|
"double3": -12.0e300
|
||||||
|
"isit double1": -12.e300
|
||||||
|
"isit double2": -12.
|
||||||
|
"yes double2": -12.0
|
||||||
|
"isit double3": .0123
|
||||||
|
"yes double3": 0.0123
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue