]> git.saurik.com Git - wxWidgets.git/commitdiff
wxMimeTypesManager::IsOfType() added (and documented)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Feb 1999 14:23:24 +0000 (14:23 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 18 Feb 1999 14:23:24 +0000 (14:23 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/mimetype.tex
src/common/mimetype.cpp

index f2b8242b776dd868bb558e687432d48a1c1c3a16..94c7191bb774f3c96cb4d5ca5a57d15381e47a51 100644 (file)
@@ -36,6 +36,15 @@ No base class.
 
 \latexignore{\rtfignore{\wxheading{Function groups}}}
 
+\membersection{Helper functions}
+
+All of these functions are static (i.e. don't need a wxMimeTypesManager object
+to call them) and provide some useful operations for string representations of
+MIME types. Their usage is recommended instead of directly working with MIME
+types using wxString functions.
+
+\helpref{IsOfType}{wxmimetypesmanagerisoftype}
+
 \membersection{Constructor and destructor}
 
 NB: You won't normally need to use more than one wxMimeTypesManager object in a
@@ -100,6 +109,18 @@ Gather information about the files with given MIME type and return the
 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}}
+
+This function returns TRUE if either the given {\it mimeType} is exactly the
+same as {\it wildcard} or if it has the same category and the subtype of
+{\it wildcard} is '*'. Note that the '*' wildcard is not allowed in
+{\it mimeType} itself.
+
+The comparaison 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{void}{ReadMailcap}{\param{const wxString\&}{ filename}}
index 9c9232276fe818237d1fb1438fa4b22036f36c18..2c039a62ed1215c3effb102ea614e3ca9a737435 100644 (file)
@@ -448,6 +448,28 @@ wxFileType::GetPrintCommand(wxString *printCmd,
 // wxMimeTypesManager
 // ----------------------------------------------------------------------------
 
+bool wxMimeTypesManager::IsOfType(const wxString& mimeType,
+                                  const wxString& wildcard)
+{
+    wxASSERT_MSG( mimeType.Find('*') == wxNOT_FOUND,
+                  "first MIME type can't contain wildcards" );
+
+    // all comparaisons are case insensitive (2nd arg of IsSameAs() is FALSE)
+    if ( wildcard.BeforeFirst('/').IsSameAs(mimeType.BeforeFirst('/'), FALSE) )
+    {
+        wxString strSubtype = wildcard.AfterFirst('/');
+
+        if ( strSubtype == '*' ||
+             strSubtype.IsSameAs(mimeType.AfterFirst('/'), FALSE) )
+        {
+            // matches (either exactly or it's a wildcard)
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
 wxMimeTypesManager::wxMimeTypesManager()
 {
     m_impl = new wxMimeTypesManagerImpl;