- static const FIND_ATTR GetAttrFromFindData(FIND_STRUCT *finddata)
- {
- #ifdef __VISUALC__
- return finddata->attrib;
- #else // Borland
- return finddata->ff_attrib;
- #endif
- }
+// Helper function checking that the contents of the given FIND_STRUCT really
+// match our filter. We need to do it ourselves as native Windows functions
+// apply the filter to both the long and the short names of the file, so
+// something like "*.bar" matches "foo.bar.baz" too and not only "foo.bar", so
+// we have to double check that we have a real match.
+inline bool
+CheckFoundMatch(const FIND_STRUCT* finddata, const wxString& filter)
+{
+ // If there is no filter, the found file must be the one we really are
+ // looking for.
+ if ( filter.empty() )
+ return true;
+
+ // Otherwise do check the match validity. Notice that we must do it
+ // case-insensitively because the case of the file names is not supposed to
+ // matter under Windows.
+ wxString fn(GetNameFromFindData(finddata));
+
+ // However if the filter contains only special characters (which is a
+ // common case), we can skip the case conversion.
+ if ( filter.find_first_not_of(wxS("*?.")) == wxString::npos )
+ return fn.Matches(filter);
+
+ return fn.MakeUpper().Matches(filter.Upper());
+}