\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.
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.
+
+
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:
//
// 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();
};
// ----------------------------------------------------------------------------
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;
};
class WXDLLIMPEXP_BASE wxMBConvUTF16Base : public wxMBConv
{
-private:
- virtual size_t GetMinMBCharWidth() const { return 2; }
+public:
+ virtual size_t GetMBNulLen() const { return 2; }
};
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxMBConvUTF32Base : public wxMBConv
{
-private:
- virtual size_t GetMinMBCharWidth() const { return 4; }
+public:
+ virtual size_t GetMBNulLen() const { return 4; }
};
// ----------------------------------------------------------------------------
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() ;
// 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
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;
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); }
#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;
// 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;
};
// 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:
return res;
}
-size_t wxMBConv_iconv::GetMinMBCharWidth() const
+size_t wxMBConv_iconv::GetMBNulLen() const
{
if ( m_minMBCharWidth == 0 )
{
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:
#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;
};
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 )
{
}
}
+ bool IsOk() const { return m_ok; }
+
+public:
+ wxFontEncoding m_enc;
+ wxEncodingConverter m2w, w2m;
+
+private:
// were we initialized successfully?
bool m_ok;
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;