From c48908df67c6504891cccd34088cad955b1357ca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 25 Jul 2004 15:30:42 +0000 Subject: [PATCH] added GetHeaderValue() (patch 974427) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28473 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/locale.tex | 8 +++++++ include/wx/intl.h | 8 +++++-- src/common/intl.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/docs/latex/wx/locale.tex b/docs/latex/wx/locale.tex index a75e762e7b..ab513b33b8 100644 --- a/docs/latex/wx/locale.tex +++ b/docs/latex/wx/locale.tex @@ -551,6 +551,14 @@ Domains are searched in the last to first order, i.e. catalogs added later override those added before. +\membersection{wxLocale::GetHeaderValue}\label{wxlocalegetheadervalue} + +\constfunc{wxString}{GetHeaderValue}{\param{const char }{*szHeader}, \param{const char }{*szDomain = NULL}} + +Returns the header value for header \arg{szHeader}. The search for \arg{szHeader} is case sensitive. If an \arg{szDomain} +is passed, this domain is searched. Else all domains will be searched until a header has been found. +The return value is the value of the header if found. Else this will be empty. + \membersection{wxLocale::GetSysName}\label{wxlocalegetsysname} \constfunc{wxString}{GetSysName}{\void} diff --git a/include/wx/intl.h b/include/wx/intl.h index 6e8b273e99..294d25f5d9 100644 --- a/include/wx/intl.h +++ b/include/wx/intl.h @@ -494,16 +494,20 @@ public: // domains are searched in the last to first order, i.e. catalogs // added later override those added before. const wxChar *GetString(const wxChar *szOrigString, - const wxChar *szDomain = (const wxChar *) NULL) const; + const wxChar *szDomain = NULL) const; // plural form version of the same: const wxChar *GetString(const wxChar *szOrigString, const wxChar *szOrigString2, size_t n, - const wxChar *szDomain = (const wxChar *) NULL) const; + const wxChar *szDomain = NULL) const; // Returns the current short name for the locale const wxString& GetName() const { return m_strShort; } + // return the contents of .po file header + wxString GetHeaderValue( const wxChar* szHeader, + const wxChar* szDomain = NULL ) const; + // These two methods are for internal use only. First one creates // ms_languagesDB if it doesn't already exist, second one destroys // it. diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 317cc06e04..66107d6fa7 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -2502,6 +2502,58 @@ const wxChar *wxLocale::GetString(const wxChar *szOrigString, return pszTrans; } +wxString wxLocale::GetHeaderValue( const wxChar* szHeader, + const wxChar* szDomain ) const +{ + if ( wxIsEmpty(Header) ) + return wxEmptyString; + + wxChar const * pszTrans = NULL; + wxMsgCatalog *pMsgCat; + + if ( szDomain != NULL ) + { + pMsgCat = FindCatalog(szDomain); + + // does the catalog exist? + if ( pMsgCat == NULL ) + return wxEmptyString; + + pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1); + } + else + { + // search in all domains + for ( pMsgCat = m_pMsgCat; pMsgCat != NULL; pMsgCat = pMsgCat->m_pNext ) + { + pszTrans = pMsgCat->GetString(wxT(""), (size_t)-1); + if ( pszTrans != NULL ) // take the first found + break; + } + } + + if ( wxIsEmpty(pszTrans) ) + return wxEmptyString; + + wxChar const * pszFound = wxStrstr(pszTrans, Header); + if ( pszFound == NULL ) + return wxEmptyString; + + pszFound += wxStrlen(Header) + 2 /* ': ' */; + + // Every header is separated by \n + + wxChar const * pszEndLine = wxStrchr(pszFound, wxT('\n')); + if ( pszEndLine == NULL ) pszEndLine = pszFound + wxStrlen(pszFound); + + + // wxString( wxChar*, length); + wxString retVal( pszFound, pszEndLine - pszFound ); + + return retVal; +} + + // find catalog by name in a linked list, return NULL if !found wxMsgCatalog *wxLocale::FindCatalog(const wxChar *szDomain) const { -- 2.45.2