From e16916eae48f55d557c8165456c9bd101cdd84a0 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Fri, 29 Jun 2007 17:33:22 +0000
Subject: [PATCH] strip the leading dot from extension if present in
 GetFileTypeFromExtension()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47026 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/mimetype.tex | 21 ++++++++++++++++++---
 src/common/mimecmn.cpp     | 13 ++++++++++++-
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/docs/latex/wx/mimetype.tex b/docs/latex/wx/mimetype.tex
index d20058d4fb..fe81926997 100644
--- a/docs/latex/wx/mimetype.tex
+++ b/docs/latex/wx/mimetype.tex
@@ -51,6 +51,7 @@ No base class.
 
 \latexignore{\rtfignore{\wxheading{Function groups}}}
 
+
 \membersection{Helper functions}\label{mimehelperfunctions}
 
 All of these functions are static (i.e. don't need a wxMimeTypesManager object
@@ -60,6 +61,7 @@ types using wxString functions.
 
 \helpref{IsOfType}{wxmimetypesmanagerisoftype}
 
+
 \membersection{Constructor and destructor}\label{mimeconstructordestructor}
 
 NB: You won't normally need to use more than one wxMimeTypesManager object in a
@@ -68,16 +70,18 @@ program.
 \helpref{wxMimeTypesManager}{wxmimetypesmanagerctor}\\
 \helpref{\destruct{wxMimeTypesManager}}{wxmimetypesmanagerdtor}
 
+
 \membersection{Query database}\label{mimequerydatabase}
 
 These functions are the heart of this class: they allow to find a \helpref{file type}{wxfiletype} object
 from either file extension or MIME type.
 If the function is successful, it returns a pointer to the wxFileType object
-which {\bf must} be deleted by the caller, otherwise NULL will be returned.
+which {\bf must} be deleted by the caller, otherwise \NULL will be returned.
 
 \helpref{GetFileTypeFromMimeType}{wxmimetypesmanagergetfiletypefrommimetype}\\
 \helpref{GetFileTypeFromExtension}{wxmimetypesmanagergetfiletypefromextension}
 
+
 \membersection{Initialization functions}\label{wxmimetypesmanagerinit}
 
 {\bf Unix:} These functions may be used to load additional files (except for the
@@ -95,6 +99,7 @@ information in either mailcap(5) or mime.types(5) format.
 
 }}
 
+
 \membersection{wxMimeTypesManager::wxMimeTypesManager}\label{wxmimetypesmanagerctor}
 
 \func{}{wxMimeTypesManager}{\void}
@@ -103,12 +108,14 @@ Constructor puts the object in the "working" state, no additional initialization
 are needed - but \helpref{ReadXXX}{wxmimetypesmanagerinit} may be used to load
 additional mailcap/mime.types files.
 
+
 \membersection{wxMimeTypesManager::\destruct{wxMimeTypesManager}}\label{wxmimetypesmanagerdtor}
 
 \func{}{\destruct{wxMimeTypesManager}}{\void}
 
 Destructor is not virtual, so this class should not be derived from.
 
+
 \membersection{wxMimeTypesManager::AddFallbacks}\label{wxmimetypesmanageraddfallbacks}
 
 \func{void}{AddFallbacks}{\param{const wxFileTypeInfo *}{fallbacks}}
@@ -120,22 +127,28 @@ and extensions that might not be present in the system MIME database.
 
 Please see the typetest sample for an example of using it.
 
+
 \membersection{wxMimeTypesManager::GetFileTypeFromExtension}\label{wxmimetypesmanagergetfiletypefromextension}
 
 \func{wxFileType*}{GetFileTypeFromExtension}{\param{const wxString\&}{ extension}}
 
 Gather information about the files with given extension and return the
-corresponding \helpref{wxFileType}{wxfiletype} object or NULL if the extension
+corresponding \helpref{wxFileType}{wxfiletype} object or \NULL if the extension
 is unknown.
 
+The \arg{extension} parameter may have, or not, the leading dot, if it has it,
+it is stripped automatically. It must not however be empty.
+
+
 \membersection{wxMimeTypesManager::GetFileTypeFromMimeType}\label{wxmimetypesmanagergetfiletypefrommimetype}
 
 \func{wxFileType*}{GetFileTypeFromMimeType}{\param{const wxString\&}{ mimeType}}
 
 Gather information about the files with given MIME type and return the
-corresponding \helpref{wxFileType}{wxfiletype} object or NULL if the MIME type
+corresponding \helpref{wxFileType}{wxfiletype} object or \NULL if the MIME type
 is unknown.
 
+
 \membersection{wxMimeTypesManager::IsOfType}\label{wxmimetypesmanagerisoftype}
 
 \func{bool}{IsOfType}{\param{const wxString\&}{ mimeType}, \param{const wxString\&}{ wildcard}}
@@ -148,6 +161,7 @@ same as {\it wildcard} or if it has the same category and the subtype of
 The comparison don by this function is case insensitive so it is not
 necessary to convert the strings to the same case before calling it.
 
+
 \membersection{wxMimeTypesManager::ReadMailcap}\label{wxmimetypesmanagerreadmailcap}
 
 \func{bool}{ReadMailcap}{\param{const wxString\&}{ filename}, \param{bool}{ fallback = false}}
@@ -165,6 +179,7 @@ will not happen if this parameter is set to true (default is false).
 The return value is true if there were no errors in the file or false
 otherwise.
 
+
 \membersection{wxMimeTypesManager::ReadMimeTypes}\label{wxmimetypesmanagerreadmimetypes}
 
 \func{bool}{ReadMimeTypes}{\param{const wxString\&}{ filename}}
diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp
index 21eb8f5c0f..bbd1d1e86d 100644
--- a/src/common/mimecmn.cpp
+++ b/src/common/mimecmn.cpp
@@ -636,7 +636,18 @@ wxFileType *
 wxMimeTypesManager::GetFileTypeFromExtension(const wxString& ext)
 {
     EnsureImpl();
-    wxFileType *ft = m_impl->GetFileTypeFromExtension(ext);
+
+    wxString::const_iterator i = ext.begin();
+    const wxString::const_iterator end = ext.end();
+    wxString extWithoutDot;
+    if ( i != end && *i == '.' )
+        extWithoutDot.assign(++i, ext.end());
+    else
+        extWithoutDot = ext;
+
+    wxCHECK_MSG( !ext.empty(), NULL, _T("extension can't be empty") );
+
+    wxFileType *ft = m_impl->GetFileTypeFromExtension(extWithoutDot);
 
     if ( !ft ) {
         // check the fallbacks
-- 
2.50.0

