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
This commit is contained in:
@@ -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}
|
\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
|
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$
|
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
|
If \arg{outLen} is not-\NULL, it receives the length of the converted
|
||||||
string.
|
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
|
result in a wxWCharBuffer. The macro wxWX2WCbuf is defined as the correct
|
||||||
return type (without const).
|
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.
|
||||||
|
|
||||||
|
|
||||||
|
@@ -81,10 +81,6 @@ public:
|
|||||||
const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
|
const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
|
||||||
#endif // Unicode/ANSI
|
#endif // Unicode/ANSI
|
||||||
|
|
||||||
// virtual dtor for any base class
|
|
||||||
virtual ~wxMBConv();
|
|
||||||
|
|
||||||
private:
|
|
||||||
// this function is used in the implementation of cMB2WC() to distinguish
|
// this function is used in the implementation of cMB2WC() to distinguish
|
||||||
// between the following cases:
|
// between the following cases:
|
||||||
//
|
//
|
||||||
@@ -96,7 +92,10 @@ private:
|
|||||||
// 4 NULs (UTF-32/UCS-4 and variants): return 4 in this case
|
// 4 NULs (UTF-32/UCS-4 and variants): return 4 in this case
|
||||||
//
|
//
|
||||||
// anything else is not supported currently and -1 should be returned
|
// 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);
|
return m_conv->WC2MB(out, in, outLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
virtual size_t GetMBNulLen() const
|
||||||
virtual size_t GetMinMBCharWidth() const
|
|
||||||
{
|
{
|
||||||
// cast needed to call a private function
|
// cast needed to call a private function
|
||||||
return ((wxConvBrokenFileNames *)m_conv)->GetMinMBCharWidth();
|
return m_conv->GetMBNulLen();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
// the conversion object we forward to
|
// the conversion object we forward to
|
||||||
wxMBConv *m_conv;
|
wxMBConv *m_conv;
|
||||||
};
|
};
|
||||||
@@ -188,8 +186,8 @@ private:
|
|||||||
|
|
||||||
class WXDLLIMPEXP_BASE wxMBConvUTF16Base : public wxMBConv
|
class WXDLLIMPEXP_BASE wxMBConvUTF16Base : public wxMBConv
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
virtual size_t GetMinMBCharWidth() const { return 2; }
|
virtual size_t GetMBNulLen() const { return 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -220,8 +218,8 @@ public:
|
|||||||
|
|
||||||
class WXDLLIMPEXP_BASE wxMBConvUTF32Base : public wxMBConv
|
class WXDLLIMPEXP_BASE wxMBConvUTF32Base : public wxMBConv
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
virtual size_t GetMinMBCharWidth() const { return 4; }
|
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 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 WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
|
||||||
|
virtual size_t GetMBNulLen() const;
|
||||||
|
|
||||||
void Clear() ;
|
void Clear() ;
|
||||||
|
|
||||||
@@ -284,8 +283,6 @@ private:
|
|||||||
// charset string
|
// charset string
|
||||||
void SetName(const wxChar *charset);
|
void SetName(const wxChar *charset);
|
||||||
|
|
||||||
virtual size_t GetMinMBCharWidth() const;
|
|
||||||
|
|
||||||
|
|
||||||
// note that we can't use wxString here because of compilation
|
// note that we can't use wxString here because of compilation
|
||||||
// dependencies: we're included from wx/string.h
|
// dependencies: we're included from wx/string.h
|
||||||
|
@@ -219,7 +219,7 @@ wxMBConv::cMB2WC(const char *in, size_t inLen, size_t *outLen) const
|
|||||||
if ( inLen != (size_t)-1 )
|
if ( inLen != (size_t)-1 )
|
||||||
{
|
{
|
||||||
// we need to know how to find the end of this string
|
// we need to know how to find the end of this string
|
||||||
nulLen = GetMinMBCharWidth();
|
nulLen = GetMBNulLen();
|
||||||
if ( nulLen == (size_t)-1 )
|
if ( nulLen == (size_t)-1 )
|
||||||
return wbuf;
|
return wbuf;
|
||||||
|
|
||||||
@@ -1368,6 +1368,10 @@ public:
|
|||||||
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
|
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;
|
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
|
bool IsOk() const
|
||||||
{ return (m2w != ICONV_T_INVALID) && (w2m != ICONV_T_INVALID); }
|
{ return (m2w != ICONV_T_INVALID) && (w2m != ICONV_T_INVALID); }
|
||||||
|
|
||||||
@@ -1382,10 +1386,6 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
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
|
// the name (for iconv_open()) of a wide char charset -- if none is
|
||||||
// available on this machine, it will remain NULL
|
// available on this machine, it will remain NULL
|
||||||
static wxString ms_wcCharsetName;
|
static wxString ms_wcCharsetName;
|
||||||
@@ -1394,7 +1394,7 @@ private:
|
|||||||
// different endian-ness than the native one
|
// different endian-ness than the native one
|
||||||
static bool ms_wcNeedsSwap;
|
static bool ms_wcNeedsSwap;
|
||||||
|
|
||||||
// cached result of GetMinMBCharWidth(); set to 0 meaning "unknown"
|
// cached result of GetMBNulLen(); set to 0 meaning "unknown"
|
||||||
// initially
|
// initially
|
||||||
size_t m_minMBCharWidth;
|
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
|
// 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
|
// NUL-terminated strings and UTF-16/32 which are terminated with 2/4 NULs
|
||||||
size_t inbuf;
|
size_t inbuf;
|
||||||
const size_t nulLen = GetMinMBCharWidth();
|
const size_t nulLen = GetMBNulLen();
|
||||||
switch ( nulLen )
|
switch ( nulLen )
|
||||||
{
|
{
|
||||||
default:
|
default:
|
||||||
@@ -1697,7 +1697,7 @@ size_t wxMBConv_iconv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxMBConv_iconv::GetMinMBCharWidth() const
|
size_t wxMBConv_iconv::GetMBNulLen() const
|
||||||
{
|
{
|
||||||
if ( m_minMBCharWidth == 0 )
|
if ( m_minMBCharWidth == 0 )
|
||||||
{
|
{
|
||||||
@@ -1930,6 +1930,44 @@ public:
|
|||||||
return len - 1;
|
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; }
|
bool IsOk() const { return m_CodePage != -1; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -1988,48 +2026,11 @@ private:
|
|||||||
#endif
|
#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
|
// the code page we're working with
|
||||||
long m_CodePage;
|
long m_CodePage;
|
||||||
|
|
||||||
// cached result of GetMinMBCharWidth(), set to 0 initially meaning
|
// cached result of GetMBNulLen(), set to 0 initially meaning
|
||||||
// "unknown"
|
// "unknown"
|
||||||
size_t m_minMBCharWidth;
|
size_t m_minMBCharWidth;
|
||||||
};
|
};
|
||||||
@@ -2665,14 +2666,7 @@ public:
|
|||||||
return inbuf;
|
return inbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsOk() const { return m_ok; }
|
virtual size_t GetMBNulLen() const
|
||||||
|
|
||||||
public:
|
|
||||||
wxFontEncoding m_enc;
|
|
||||||
wxEncodingConverter m2w, w2m;
|
|
||||||
|
|
||||||
private:
|
|
||||||
virtual size_t GetMinMBCharWidth() const
|
|
||||||
{
|
{
|
||||||
switch ( m_enc )
|
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?
|
// were we initialized successfully?
|
||||||
bool m_ok;
|
bool m_ok;
|
||||||
|
|
||||||
@@ -3081,14 +3082,13 @@ size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t wxCSConv::GetMinMBCharWidth() const
|
size_t wxCSConv::GetMBNulLen() const
|
||||||
{
|
{
|
||||||
CreateConvIfNeeded();
|
CreateConvIfNeeded();
|
||||||
|
|
||||||
if ( m_convReal )
|
if ( m_convReal )
|
||||||
{
|
{
|
||||||
// cast needed just to call private function of m_convReal
|
return m_convReal->GetMBNulLen();
|
||||||
return ((wxCSConv *)m_convReal)->GetMinMBCharWidth();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user