new convencience function for checking valid IDs (includes unit tests)
This commit is contained in:
@ -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
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
Reference in New Issue
Block a user