From ea3fc9f27f6feb14ea3b7cfc8b1e921195dd3c3f Mon Sep 17 00:00:00 2001 From: neoraider Date: Sat, 29 Sep 2007 20:03:02 +0000 Subject: zoomedit: IdManager: Id-Validierung verbessert. --- IdManager.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'IdManager.cpp') 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; -- cgit v1.2.3