fix config::valid_id()

previously config::valid_id() had the following issues:
1) It passed its parameter by copy.
2) It used isalnum, which depends on the current locale, this means that
its reults might be different on different machines and it also means
that its slow becasue it must check the current locale.
This commit is contained in:
gfgtdf 2016-02-08 21:10:20 +01:00
parent 84ff8f4d96
commit c55faadecc
2 changed files with 6 additions and 3 deletions

View File

@ -480,13 +480,16 @@ config &config::operator=(config &&cfg)
}
#endif
bool config::valid_id(const std::string id)
bool config::valid_id(const std::string& id)
{
if (id.empty()) {
return false;
}
BOOST_FOREACH(char c, id) {
if (!isalnum(c) && c != '_') {
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_') {
//valid character.
}
else {
return false;
}
}

View File

@ -105,7 +105,7 @@ public:
~config();
// Verifies that the string can be used as an attribute or tag name
static bool valid_id(std::string);
static bool valid_id(const std::string& id);
#ifdef HAVE_CXX11
explicit operator bool() const