Skip to content

Commit

Permalink
[FEATURE] More restrictive checking of boolean parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Dec 28, 2021
1 parent d8aa049 commit 2a86877
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 1 addition & 2 deletions paramkit/include/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,7 @@ namespace paramkit {
this->value = true;
return true;
}
this->value = loadBoolean(arg);
return true;
return loadBoolean(arg, this->value);
}

bool value;
Expand Down
18 changes: 15 additions & 3 deletions paramkit/include/pk_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,30 @@ namespace paramkit {
}

template <typename T_CHAR>
bool loadBoolean(const T_CHAR *str1)
bool loadBoolean(IN const T_CHAR *str1, OUT bool &value)
{
std::string str = to_string(str1);
if (util::strequals(str, "True") || util::strequals(str, "on") || util::strequals(str, "yes")) {
value = true;
return true;
}
if (util::strequals(str, "False") || util::strequals(str, "off") || util::strequals(str, "no")) {
value = false;
return true;
}
if (!is_dec(str.c_str(), str.length())) {
return false;
}
const int val = loadInt(str.c_str(), false);
if (val == 0) return false;
return true;
if (val == 0) {
value = false;
return true;
}
if (val == 1) {
value = true;
return true;
}
return false;
}

//! Copy the std::string/std::wstring value into an buffer of a given character count
Expand Down

0 comments on commit 2a86877

Please sign in to comment.