summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--IdManager.cpp14
-rw-r--r--IdManager.h4
2 files changed, 13 insertions, 5 deletions
diff --git a/IdManager.cpp b/IdManager.cpp
index a610036..d60417c 100644
--- a/IdManager.cpp
+++ b/IdManager.cpp
@@ -13,9 +13,13 @@ bool IdManager::remove(const std::string &id) {
return (usedIds.erase(id) > 0);
}
-bool IdManager::valid(const std::string &id) const {
+bool IdManager::isValid(const std::string &id) const {
if(id.empty()) return false;
if(id[0] >= '0' && id[0] <= '9') return false;
+ if(id.size() >= 3) {
+ if(std::tolower(id[0]) == 'x' && std::tolower(id[1]) == 'm' && std::tolower(id[2]) == 'l')
+ return false;
+ }
for(std::string::const_iterator c = id.begin(); c != id.end(); c++) {
if(!(*c >= '0' && *c <= '9') && !(*c >= 'A' && *c <= 'Z') && !(*c >= 'a' && *c <= 'z')
@@ -27,13 +31,15 @@ bool IdManager::valid(const std::string &id) const {
}
bool IdManager::unique(const std::string &id) const {
- if(!valid(id)) return false;
-
return (usedIds.find(id) == usedIds.end());
}
+bool IdManager::valid(const std::string &id) const {
+ return isValid(id) && unique(id);
+}
+
std::string IdManager::generate(const std::string &prefix) {
- if(!valid(prefix)) return std::string();
+ if(!isValid(prefix)) return std::string();
unsigned long n = 0;
diff --git a/IdManager.h b/IdManager.h
index bc3efb7..8f846a9 100644
--- a/IdManager.h
+++ b/IdManager.h
@@ -11,12 +11,14 @@ class IdManager {
std::set<std::string> usedIds;
std::map<std::string, unsigned long> prefixMap;
+ bool isValid(const std::string &id) const;
+ bool unique(const std::string &id) const;
+
public:
bool add(const std::string &id);
bool remove(const std::string &id);
bool valid(const std::string &id) const;
- bool unique(const std::string &id) const;
std::string generate(const std::string &prefix);
};