]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxFilterClassFactory::PopExtension().
authorMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 26 Oct 2006 22:43:15 +0000 (22:43 +0000)
committerMichael Wetherell <mike.wetherell@ntlworld.com>
Thu, 26 Oct 2006 22:43:15 +0000 (22:43 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/stream.h
src/common/stream.cpp

index 6d3da3c9146c6e7bc4bbbd9d42e7a4eb309317a9..cad5148ab906bb41eede60c7aa4d15697be0919d 100644 (file)
@@ -346,6 +346,7 @@ public:
     virtual wxFilterOutputStream *NewStream(wxOutputStream *stream) const = 0;
 
     wxString GetProtocol() const { return wxString(*GetProtocols()); }
+    wxString PopExtension(const wxString& location) const;
 
     virtual const wxChar * const *GetProtocols(wxStreamProtocolType type
                                                = wxSTREAM_PROTOCOL) const = 0;
@@ -370,6 +371,8 @@ protected:
     wxFilterClassFactory& operator=(const wxFilterClassFactory&)
         { return *this; }
 
+    wxString::size_type FindExtension(const wxChar *location) const;
+
 private:
     static wxFilterClassFactory *sm_first;
     wxFilterClassFactory *m_next;
index 618ae6ed322cf7138a15cbc0ea55247c8de0a695..8aa12b5e24609c88a5dbbfadc2a5fa6e9a80fb8f 100644 (file)
@@ -1113,27 +1113,37 @@ IMPLEMENT_ABSTRACT_CLASS(wxFilterClassFactory, wxObject)
 
 wxFilterClassFactory *wxFilterClassFactory::sm_first = NULL;
 
-bool wxFilterClassFactory::CanHandle(const wxChar *protocol,
-                                     wxStreamProtocolType type) const
+wxString wxFilterClassFactory::PopExtension(const wxString& location) const
 {
-    if (type == wxSTREAM_FILEEXTENSION)
-    {
-        size_t len = wxStrlen(protocol);
+    return location.substr(0, FindExtension(location));
+}
 
-        for (const wxChar * const *p = GetProtocols(type); p && *p; p++)
-        {
-            size_t l = wxStrlen(*p);
+wxString::size_type wxFilterClassFactory::FindExtension(const wxChar *location) const
+{
+    size_t len = wxStrlen(location);
 
-            if (l <= len && wxStrcmp(*p, protocol + len - l) == 0)
-                return true;
-        }
+    for (const wxChar *const *p = GetProtocols(wxSTREAM_FILEEXTENSION);
+         p && *p;
+         p++)
+    {
+        size_t l = wxStrlen(*p);
+
+        if (l <= len && wxStrcmp(*p, location + len - l) == 0)
+            return len - l;
     }
+
+    return wxString::npos;
+}
+
+bool wxFilterClassFactory::CanHandle(const wxChar *protocol,
+                                     wxStreamProtocolType type) const
+{
+    if (type == wxSTREAM_FILEEXTENSION)
+        return FindExtension(protocol) != wxString::npos;
     else
-    {
-        for (const wxChar * const *p = GetProtocols(type); p && *p; p++)
+        for (const wxChar *const *p = GetProtocols(type); p && *p; p++)
             if (wxStrcmp(*p, protocol) == 0)
                 return true;
-    }
 
     return false;
 }