Library: Added <valid> element that is used to define valid input values for functions
This commit is contained in:
parent
85c62f98d7
commit
be03d4718a
|
@ -112,6 +112,7 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
bool notuninit = false;
|
bool notuninit = false;
|
||||||
bool formatstr = false;
|
bool formatstr = false;
|
||||||
bool strz = false;
|
bool strz = false;
|
||||||
|
std::string valid;
|
||||||
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
|
for (const tinyxml2::XMLElement *argnode = functionnode->FirstChildElement(); argnode; argnode = argnode->NextSiblingElement()) {
|
||||||
if (strcmp(argnode->Name(), "not-null") == 0)
|
if (strcmp(argnode->Name(), "not-null") == 0)
|
||||||
notnull = true;
|
notnull = true;
|
||||||
|
@ -121,6 +122,25 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
formatstr = true;
|
formatstr = true;
|
||||||
else if (strcmp(argnode->Name(), "strz") == 0)
|
else if (strcmp(argnode->Name(), "strz") == 0)
|
||||||
strz = true;
|
strz = true;
|
||||||
|
else if (strcmp(argnode->Name(), "valid") == 0) {
|
||||||
|
// Validate the validation expression
|
||||||
|
const char *p = argnode->GetText();
|
||||||
|
if (!std::isdigit(*p))
|
||||||
|
return false;
|
||||||
|
for (; *p; p++) {
|
||||||
|
if (std::isdigit(*p))
|
||||||
|
continue;
|
||||||
|
if (*p == '-' && std::isdigit(*(p-1)))
|
||||||
|
continue;
|
||||||
|
if (*p == ',' && *(p+1) != ',')
|
||||||
|
continue;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set validation expression
|
||||||
|
valid = argnode->GetText();
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -128,6 +148,7 @@ bool Library::load(const tinyxml2::XMLDocument &doc)
|
||||||
argumentChecks[name][nr].notuninit = notuninit;
|
argumentChecks[name][nr].notuninit = notuninit;
|
||||||
argumentChecks[name][nr].formatstr = formatstr;
|
argumentChecks[name][nr].formatstr = formatstr;
|
||||||
argumentChecks[name][nr].strz = strz;
|
argumentChecks[name][nr].strz = strz;
|
||||||
|
argumentChecks[name][nr].valid = valid;
|
||||||
} else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
|
} else if (strcmp(functionnode->Name(), "ignorefunction") == 0) {
|
||||||
_ignorefunction[name] = (strcmp(functionnode->GetText(), "true") == 0);
|
_ignorefunction[name] = (strcmp(functionnode->GetText(), "true") == 0);
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -100,6 +100,7 @@ public:
|
||||||
bool notuninit;
|
bool notuninit;
|
||||||
bool formatstr;
|
bool formatstr;
|
||||||
bool strz;
|
bool strz;
|
||||||
|
std::string valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
// function name, argument nr => argument data
|
// function name, argument nr => argument data
|
||||||
|
|
|
@ -79,6 +79,9 @@ private:
|
||||||
" <arg nr=\"4\">\n"
|
" <arg nr=\"4\">\n"
|
||||||
" <strz/>\n"
|
" <strz/>\n"
|
||||||
" </arg>\n"
|
" </arg>\n"
|
||||||
|
" <arg nr=\"5\">\n"
|
||||||
|
" <valid>1-</valid>\n"
|
||||||
|
" </arg>\n"
|
||||||
" </function>\n"
|
" </function>\n"
|
||||||
"</def>";
|
"</def>";
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
|
@ -90,6 +93,7 @@ private:
|
||||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][2].notnull);
|
ASSERT_EQUALS(true, library.argumentChecks["foo"][2].notnull);
|
||||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][3].formatstr);
|
ASSERT_EQUALS(true, library.argumentChecks["foo"][3].formatstr);
|
||||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][4].strz);
|
ASSERT_EQUALS(true, library.argumentChecks["foo"][4].strz);
|
||||||
|
ASSERT_EQUALS("1-", library.argumentChecks["foo"][5].valid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void memory() {
|
void memory() {
|
||||||
|
|
Loading…
Reference in New Issue