diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2006-12-18 17:06:44 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2006-12-18 17:06:44 +0000 |
commit | d07fdae285690f699a70f97f36232e516dcad2bc (patch) | |
tree | c239def689c5e6cc53ac76dbe3e60ec11c306964 /cpp/src/IceUtil/StringUtil.cpp | |
parent | Fixed tryLock() comment (diff) | |
download | ice-d07fdae285690f699a70f97f36232e516dcad2bc.tar.bz2 ice-d07fdae285690f699a70f97f36232e516dcad2bc.tar.xz ice-d07fdae285690f699a70f97f36232e516dcad2bc.zip |
Object adapter properties now prefixed by "Ice.OA."
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r-- | cpp/src/IceUtil/StringUtil.cpp | 67 |
1 files changed, 33 insertions, 34 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp index 2f1fa474dda..1b90f0ad3e8 100644 --- a/cpp/src/IceUtil/StringUtil.cpp +++ b/cpp/src/IceUtil/StringUtil.cpp @@ -337,51 +337,50 @@ IceUtil::checkQuote(const string& s, string::size_type start) // // Match `s' against the pattern `pat'. A * in the pattern acts -// as a wildcard: it matches any non-empty sequence of characters -// other than a period (`.'). We match by hand here because -// it's portable across platforms (whereas regex() isn't). +// as a wildcard: it matches any non-empty sequence of characters. +// We match by hand here because it's portable across platforms +// (whereas regex() isn't). Only one * per pattern is supported. // bool -IceUtil::match(const string& s, const string& pat, bool matchPeriod) +IceUtil::match(const string& s, const string& pat, bool emptyMatch) { assert(!s.empty()); assert(!pat.empty()); - if(pat.find('*') == string::npos) + // + // If pattern does not contain a wildcard just compare strings. + // + string::size_type beginIndex = pat.find('*'); + if(beginIndex == string::npos) { return s == pat; } - string::size_type sIndex = 0; - string::size_type patIndex = 0; - do + // + // Make sure start of the strings match + // + if(s.substr(0, beginIndex) != pat.substr(0, beginIndex)) { - if(pat[patIndex] == '*') - { - // - // Don't allow matching x..y against x.*.y if requested -- star matches non-empty sequence only. - // - if(!matchPeriod && s[sIndex] == '.') - { - return false; - } - while(sIndex < s.size() && (matchPeriod || s[sIndex] != '.')) - { - ++sIndex; - } - patIndex++; - } - else - { - if(pat[patIndex] != s[sIndex]) - { - return false; - } - ++sIndex; - ++patIndex; - } + return false; + } + + // + // Make sure there is something present in the middle to match the + // wildcard. If emptyMatch is true, allow a match of "". + // + string::size_type endIndex = s.length() - (pat.length() - beginIndex - 1); + if(endIndex < beginIndex || (!emptyMatch && endIndex == beginIndex)) + { + return false; + } + + // + // Make sure end of the strings match + // + if(s.substr(endIndex, s.length()) != pat.substr(beginIndex + 1, pat.length())) + { + return false; } - while(sIndex < s.size() && patIndex < pat.size()); - return sIndex == s.size() && patIndex == pat.size(); + return true; } |