From: Vadim Zeitlin Date: Tue, 4 Apr 2006 07:49:08 +0000 (+0000) Subject: renamed GetMinMBCharWidth() to GetMBNulLen(), made it public and documented it X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7ef3ab50e9705c2724f74ef4fb275030d6fbe589 renamed GetMinMBCharWidth() to GetMBNulLen(), made it public and documented it git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38540 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/mbconv.tex b/docs/latex/wx/mbconv.tex index 5071ae595e..f1cc6811e2 100644 --- a/docs/latex/wx/mbconv.tex +++ b/docs/latex/wx/mbconv.tex @@ -115,7 +115,8 @@ trailing \NUL character(s). If the string is not \NUL-terminated, a temporary \NUL-terminated copy of it suitable for passing to \helpref{MB2WC}{wxmbconvmb2wc} is made, so it is more efficient to ensure that the string is does have the appropriate number of \NUL bytes (which is usually $1$ but may be $2$ or $4$ -for UTF-16 or UTF-32), especially for long strings. +for UTF-16 or UTF-32, see \helpref{GetMBNulLen}{wxmbconvgetmbnullen}), +especially for long strings. If \arg{outLen} is not-\NULL, it receives the length of the converted string. @@ -189,3 +190,14 @@ it returns the parameter unaltered. If wxChar is char, it returns the result in a wxWCharBuffer. The macro wxWX2WCbuf is defined as the correct return type (without const). + +\membersection{wxMBConv::GetMBNulLen}\label{wxmbconvgetmbnullen} + +\constfunc{size\_t}{GetMBNulLen}{\void} + +This function returns $1$ for most of the multibyte encodings in which the +string is terminated by a single \NUL, $2$ for UTF-16 and $4$ for UTF-32 for +which the string is terminated with $2$ and $4$ \NUL characters respectively. +The other cases are not currently supported and $-1$ is returned for them. + + diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 32a9611175..a5f0423c3a 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -81,10 +81,6 @@ public: const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); } #endif // Unicode/ANSI - // virtual dtor for any base class - virtual ~wxMBConv(); - -private: // this function is used in the implementation of cMB2WC() to distinguish // between the following cases: // @@ -96,7 +92,10 @@ private: // 4 NULs (UTF-32/UCS-4 and variants): return 4 in this case // // anything else is not supported currently and -1 should be returned - virtual size_t GetMinMBCharWidth() const { return 1; } + virtual size_t GetMBNulLen() const { return 1; } + + // virtual dtor for any base class + virtual ~wxMBConv(); }; // ---------------------------------------------------------------------------- @@ -136,14 +135,13 @@ public: return m_conv->WC2MB(out, in, outLen); } -private: - virtual size_t GetMinMBCharWidth() const + virtual size_t GetMBNulLen() const { // cast needed to call a private function - return ((wxConvBrokenFileNames *)m_conv)->GetMinMBCharWidth(); + return m_conv->GetMBNulLen(); } - +private: // the conversion object we forward to wxMBConv *m_conv; }; @@ -188,8 +186,8 @@ private: class WXDLLIMPEXP_BASE wxMBConvUTF16Base : public wxMBConv { -private: - virtual size_t GetMinMBCharWidth() const { return 2; } +public: + virtual size_t GetMBNulLen() const { return 2; } }; // ---------------------------------------------------------------------------- @@ -220,8 +218,8 @@ public: class WXDLLIMPEXP_BASE wxMBConvUTF32Base : public wxMBConv { -private: - virtual size_t GetMinMBCharWidth() const { return 4; } +public: + virtual size_t GetMBNulLen() const { return 4; } }; // ---------------------------------------------------------------------------- @@ -267,6 +265,7 @@ public: virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const; virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const; + virtual size_t GetMBNulLen() const; void Clear() ; @@ -284,8 +283,6 @@ private: // charset string void SetName(const wxChar *charset); - virtual size_t GetMinMBCharWidth() const; - // note that we can't use wxString here because of compilation // dependencies: we're included from wx/string.h diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 1d702be11c..39a6996c19 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -219,7 +219,7 @@ wxMBConv::cMB2WC(const char *in, size_t inLen, size_t *outLen) const if ( inLen != (size_t)-1 ) { // we need to know how to find the end of this string - nulLen = GetMinMBCharWidth(); + nulLen = GetMBNulLen(); if ( nulLen == (size_t)-1 ) return wbuf; @@ -1368,6 +1368,10 @@ public: virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const; virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const; + // classify this encoding as explained in wxMBConv::GetMBNulLen() + // comment + virtual size_t GetMBNulLen() const; + bool IsOk() const { return (m2w != ICONV_T_INVALID) && (w2m != ICONV_T_INVALID); } @@ -1382,10 +1386,6 @@ protected: #endif private: - // classify this encoding as explained in wxMBConv::GetMinMBCharWidth() - // comment - virtual size_t GetMinMBCharWidth() const; - // the name (for iconv_open()) of a wide char charset -- if none is // available on this machine, it will remain NULL static wxString ms_wcCharsetName; @@ -1394,7 +1394,7 @@ private: // different endian-ness than the native one static bool ms_wcNeedsSwap; - // cached result of GetMinMBCharWidth(); set to 0 meaning "unknown" + // cached result of GetMBNulLen(); set to 0 meaning "unknown" // initially size_t m_minMBCharWidth; }; @@ -1543,7 +1543,7 @@ size_t wxMBConv_iconv::MB2WC(wchar_t *buf, const char *psz, size_t n) const // find the string length: notice that must be done differently for // NUL-terminated strings and UTF-16/32 which are terminated with 2/4 NULs size_t inbuf; - const size_t nulLen = GetMinMBCharWidth(); + const size_t nulLen = GetMBNulLen(); switch ( nulLen ) { default: @@ -1697,7 +1697,7 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const return res; } -size_t wxMBConv_iconv::GetMinMBCharWidth() const +size_t wxMBConv_iconv::GetMBNulLen() const { if ( m_minMBCharWidth == 0 ) { @@ -1930,6 +1930,44 @@ public: return len - 1; } + virtual size_t GetMBNulLen() const + { + if ( m_minMBCharWidth == 0 ) + { + int len = ::WideCharToMultiByte + ( + m_CodePage, // code page + 0, // no flags + L"", // input string + 1, // translate just the NUL + NULL, // output buffer + 0, // and its size + NULL, // no replacement char + NULL // [out] don't care if it was used + ); + + wxMBConv_win32 * const self = wxConstCast(this, wxMBConv_win32); + switch ( len ) + { + default: + wxLogDebug(_T("Unexpected NUL length %d"), len); + // fall through + + case 0: + self->m_minMBCharWidth = (size_t)-1; + break; + + case 1: + case 2: + case 4: + self->m_minMBCharWidth = len; + break; + } + } + + return m_minMBCharWidth; + } + bool IsOk() const { return m_CodePage != -1; } private: @@ -1988,48 +2026,11 @@ private: #endif } - virtual size_t GetMinMBCharWidth() const - { - if ( m_minMBCharWidth == 0 ) - { - int len = ::WideCharToMultiByte - ( - m_CodePage, // code page - 0, // no flags - L"", // input string - 1, // translate just the NUL - NULL, // output buffer - 0, // and its size - NULL, // no replacement char - NULL // [out] don't care if it was used - ); - - wxMBConv_win32 * const self = wxConstCast(this, wxMBConv_win32); - switch ( len ) - { - default: - wxLogDebug(_T("Unexpected NUL length %d"), len); - // fall through - - case 0: - self->m_minMBCharWidth = (size_t)-1; - break; - - case 1: - case 2: - case 4: - self->m_minMBCharWidth = len; - break; - } - } - - return m_minMBCharWidth; - } // the code page we're working with long m_CodePage; - // cached result of GetMinMBCharWidth(), set to 0 initially meaning + // cached result of GetMBNulLen(), set to 0 initially meaning // "unknown" size_t m_minMBCharWidth; }; @@ -2665,14 +2666,7 @@ public: return inbuf; } - bool IsOk() const { return m_ok; } - -public: - wxFontEncoding m_enc; - wxEncodingConverter m2w, w2m; - -private: - virtual size_t GetMinMBCharWidth() const + virtual size_t GetMBNulLen() const { switch ( m_enc ) { @@ -2689,6 +2683,13 @@ private: } } + bool IsOk() const { return m_ok; } + +public: + wxFontEncoding m_enc; + wxEncodingConverter m2w, w2m; + +private: // were we initialized successfully? bool m_ok; @@ -3081,14 +3082,13 @@ size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const return len; } -size_t wxCSConv::GetMinMBCharWidth() const +size_t wxCSConv::GetMBNulLen() const { CreateConvIfNeeded(); if ( m_convReal ) { - // cast needed just to call private function of m_convReal - return ((wxCSConv *)m_convReal)->GetMinMBCharWidth(); + return m_convReal->GetMBNulLen(); } return 1;