From: Vadim Zeitlin Date: Thu, 18 Feb 1999 14:23:24 +0000 (+0000) Subject: wxMimeTypesManager::IsOfType() added (and documented) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a5a19b836081432731d0302c95985fbb4ebc70d8 wxMimeTypesManager::IsOfType() added (and documented) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1717 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/mimetype.tex b/docs/latex/wx/mimetype.tex index f2b8242b77..94c7191bb7 100644 --- a/docs/latex/wx/mimetype.tex +++ b/docs/latex/wx/mimetype.tex @@ -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}} diff --git a/src/common/mimetype.cpp b/src/common/mimetype.cpp index 9c9232276f..2c039a62ed 100644 --- a/src/common/mimetype.cpp +++ b/src/common/mimetype.cpp @@ -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;