summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/StringUtil.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2005-01-27 14:09:35 +0000
committerBenoit Foucher <benoit@zeroc.com>2005-01-27 14:09:35 +0000
commit9b9bd3568a59a4b111953bc016a9bcdf08ca728c (patch)
treec644accf965ae25c0c4f8d318a5a19500d36f38a /cpp/src/IceUtil/StringUtil.cpp
parentConnection validation now checks for Ice.Override.ConnectTimeout (diff)
downloadice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.tar.bz2
ice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.tar.xz
ice-9b9bd3568a59a4b111953bc016a9bcdf08ca728c.zip
Added 'object list' and 'object describe' IcePack admin commands.
Diffstat (limited to 'cpp/src/IceUtil/StringUtil.cpp')
-rw-r--r--cpp/src/IceUtil/StringUtil.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/cpp/src/IceUtil/StringUtil.cpp b/cpp/src/IceUtil/StringUtil.cpp
index a232d85dfac..72bb715369f 100644
--- a/cpp/src/IceUtil/StringUtil.cpp
+++ b/cpp/src/IceUtil/StringUtil.cpp
@@ -255,3 +255,51 @@ IceUtil::checkQuote(const string& s, string::size_type start)
}
return 0; // Not quoted.
}
+
+//
+// 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).
+//
+bool
+IceUtil::match(const string& s, const string& pat)
+{
+ assert(!s.empty());
+ assert(!pat.empty());
+
+ if(pat.find('*') == string::npos)
+ {
+ return s == pat;
+ }
+
+ string::size_type sIndex = 0;
+ string::size_type patIndex = 0;
+ do
+ {
+ if(pat[patIndex] == '*')
+ {
+ if(s[sIndex] == '.') // Don't allow matching x..y against x.*.y -- star matches non-empty sequence only.
+ {
+ return false;
+ }
+ while(sIndex < s.size() && s[sIndex] != '.')
+ {
+ ++sIndex;
+ }
+ patIndex++;
+ }
+ else
+ {
+ if(pat[patIndex] != s[sIndex])
+ {
+ return false;
+ }
+ ++sIndex;
+ ++patIndex;
+ }
+ }
+ while(sIndex < s.size() && patIndex < pat.size());
+
+ return sIndex == s.size() && patIndex == pat.size();
+}