]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/mimetype.cpp
wxTextFile::Eof() bug corrected (always returned FALSE before)
[wxWidgets.git] / src / common / mimetype.cpp
index 1e268d586d11ac160430a46bc9f3650c1afc592c..9f7cd6b0bfe9ce3762fc1186b862bed73010e31f 100644 (file)
@@ -170,7 +170,7 @@ public:
 //  * compose and composetyped fields are used to determine the program to be
 //    called to create a new message pert in the specified format (unused).
 //
-// Parameter/filename xpansion: 
+// Parameter/filename xpansion:
 //  * %s is replaced with the (full) file name
 //  * %t is replaced with MIME type/subtype of the entry
 //  * for multipart type only %n is replaced with the nnumber of parts and %F is
@@ -189,7 +189,7 @@ public:
 // comments. Each record has one of two following forms:
 //  a) for "brief" format:
 //      <mime type>  <space separated list of extensions>
-//  b) for "expanded" format: 
+//  b) for "expanded" format:
 //      type=<mime type> \ desc="<description>" \ exts="ext"
 //
 // We try to autodetect the format of mime.types: if a non-comment line starts
@@ -337,8 +337,8 @@ wxString wxFileType::ExpandCommand(const wxString& command,
                 case 's':
                     // '%s' expands into file name (quoted because it might
                     // contain spaces) - except if there are already quotes
-                    // there because otherwise some programs may get confused by
-                    // double double quotes
+                    // there because otherwise some programs may get confused
+                    // by double double quotes
 #if 0
                     if ( *(pc - 2) == '"' )
                         str << params.GetFileName();
@@ -796,8 +796,25 @@ wxMimeTypesManagerImpl::wxMimeTypesManagerImpl()
 wxFileType *
 wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext)
 {
-    wxFAIL_MSG("not implemented (must parse mime.types)");
+    size_t count = m_aExtensions.GetCount();
+    for ( size_t n = 0; n < count; n++ ) {
+        wxString extensions = m_aExtensions[n];
+        while ( !extensions.IsEmpty() ) {
+            wxString field = extensions.BeforeFirst(' ');
+            extensions = extensions.AfterFirst(' ');
+
+            // consider extensions as not being case-sensitive
+            if ( field.IsSameAs(ext, FALSE /* no case */) ) {
+                // found
+                wxFileType *fileType = new wxFileType;
+                fileType->m_impl->Init(this, n);
+
+                return fileType;
+            }
+        }
+    }
 
+    // not found
     return NULL;
 }
 
@@ -1077,8 +1094,8 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName)
                                 // is this something of the form foo=bar?
                                 const char *pEq = strchr(curField, '=');
                                 if ( pEq != NULL ) {
-                                    wxString lhs = curField.Before('='),
-                                             rhs = curField.After('=');
+                                    wxString lhs = curField.BeforeFirst('='),
+                                             rhs = curField.AfterFirst('=');
 
                                     lhs.Trim(TRUE);     // from right
                                     rhs.Trim(FALSE);    // from left
@@ -1126,7 +1143,9 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName)
                                 {
                                     // don't flood the user with error messages
                                     // if we don't understand something in his
-                                    // mailcap
+                                    // mailcap, but give them in debug mode
+                                    // because this might be useful for the
+                                    // programmer
                                     wxLogDebug
                                     (
                                       _("Mailcap file %s, line %d: unknown "