+
+//------------------------------------------------------------------------
+// wild character routines
+//------------------------------------------------------------------------
+
+bool wxIsWild( const wxString& pattern )
+{
+ for ( wxString::const_iterator p = pattern.begin(); p != pattern.end(); ++p )
+ {
+ switch ( (*p).GetValue() )
+ {
+ case wxT('?'):
+ case wxT('*'):
+ case wxT('['):
+ case wxT('{'):
+ return true;
+
+ case wxT('\\'):
+ if ( ++p == pattern.end() )
+ return false;
+ }
+ }
+ return false;
+}
+
+/*
+* Written By Douglas A. Lewis <dalewis@cs.Buffalo.EDU>
+*
+* The match procedure is public domain code (from ircII's reg.c)
+* but modified to suit our tastes (RN: No "%" syntax I guess)
+*/
+
+bool wxMatchWild( const wxString& pat, const wxString& text, bool dot_special )
+{
+ if (text.empty())
+ {
+ /* Match if both are empty. */
+ return pat.empty();
+ }
+
+ const wxChar *m = pat.c_str(),
+ *n = text.c_str(),
+ *ma = NULL,
+ *na = NULL;
+ int just = 0,
+ acount = 0,
+ count = 0;
+
+ if (dot_special && (*n == wxT('.')))
+ {
+ /* Never match so that hidden Unix files
+ * are never found. */
+ return false;
+ }
+
+ for (;;)
+ {
+ if (*m == wxT('*'))
+ {
+ ma = ++m;
+ na = n;
+ just = 1;
+ acount = count;
+ }
+ else if (*m == wxT('?'))
+ {
+ m++;
+ if (!*n++)
+ return false;
+ }
+ else
+ {
+ if (*m == wxT('\\'))
+ {
+ m++;
+ /* Quoting "nothing" is a bad thing */
+ if (!*m)
+ return false;
+ }
+ if (!*m)
+ {
+ /*
+ * If we are out of both strings or we just
+ * saw a wildcard, then we can say we have a
+ * match
+ */
+ if (!*n)
+ return true;
+ if (just)
+ return true;
+ just = 0;
+ goto not_matched;
+ }
+ /*
+ * We could check for *n == NULL at this point, but
+ * since it's more common to have a character there,
+ * check to see if they match first (m and n) and
+ * then if they don't match, THEN we can check for
+ * the NULL of n
+ */
+ just = 0;
+ if (*m == *n)
+ {
+ m++;
+ count++;
+ n++;
+ }
+ else
+ {
+
+ not_matched:
+
+ /*
+ * If there are no more characters in the
+ * string, but we still need to find another
+ * character (*m != NULL), then it will be
+ * impossible to match it
+ */
+ if (!*n)
+ return false;
+
+ if (ma)
+ {
+ m = ma;
+ n = ++na;
+ count = acount;
+ }
+ else
+ return false;
+ }
+ }
+ }
+}
+