diff options
author | neoraider <devnull@localhost> | 2007-09-29 22:03:02 +0200 |
---|---|---|
committer | neoraider <devnull@localhost> | 2007-09-29 22:03:02 +0200 |
commit | ea3fc9f27f6feb14ea3b7cfc8b1e921195dd3c3f (patch) | |
tree | c53c8477c42c070e9ab5640e051ea3978f38d2dd | |
parent | 38b318a57f0a713eb2aa8407893eea142e57427e (diff) | |
download | zoomedit-ea3fc9f27f6feb14ea3b7cfc8b1e921195dd3c3f.tar zoomedit-ea3fc9f27f6feb14ea3b7cfc8b1e921195dd3c3f.zip |
zoomedit: IdManager: Id-Validierung verbessert.
-rw-r--r-- | IdManager.cpp | 14 | ||||
-rw-r--r-- | IdManager.h | 4 |
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); }; |