new convencience function for checking valid IDs (includes unit tests)

This commit is contained in:
Axel Kohlmeyer
2021-03-02 11:01:51 -05:00
parent 0f63f07ce5
commit ca8b268ad5
3 changed files with 81 additions and 2 deletions

View File

@ -851,7 +851,7 @@ std::vector<std::string> utils::split_words(const std::string &text)
------------------------------------------------------------------------- */
bool utils::is_integer(const std::string &str) {
if (str.size() == 0) {
if (str.empty()) {
return false;
}
@ -867,7 +867,7 @@ bool utils::is_integer(const std::string &str) {
------------------------------------------------------------------------- */
bool utils::is_double(const std::string &str) {
if (str.size() == 0) {
if (str.empty()) {
return false;
}
@ -880,6 +880,22 @@ bool utils::is_double(const std::string &str) {
return true;
}
/* ----------------------------------------------------------------------
Return whether string is a valid ID string
------------------------------------------------------------------------- */
bool utils::is_id(const std::string &str) {
if (str.empty()) {
return false;
}
for (auto c : str) {
if (isalnum(c) || (c == '_')) continue;
return false;
}
return true;
}
/* ----------------------------------------------------------------------
strip off leading part of path, return just the filename
------------------------------------------------------------------------- */