fix VC++ warnings (which could be errors for the other compilers) with returning wx(W)CharBuffer
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -231,28 +231,41 @@ size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
|||||||
|
|
||||||
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
|
const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
|
||||||
{
|
{
|
||||||
if (psz)
|
if ( psz )
|
||||||
{
|
{
|
||||||
size_t nLen = MB2WC((wchar_t *) NULL, psz, 0); // return value excludes /0
|
// calculate the length of the buffer needed first
|
||||||
if (nLen == (size_t)-1)
|
size_t nLen = MB2WC(NULL, psz, 0);
|
||||||
return wxWCharBuffer((wchar_t *) NULL);
|
if ( nLen != (size_t)-1 )
|
||||||
wxWCharBuffer buf(nLen); // this allocates nLen1+
|
{
|
||||||
MB2WC((wchar_t *)(const wchar_t *) buf, psz, nLen+1);
|
// now do the actual conversion
|
||||||
return buf;
|
wxWCharBuffer buf(nLen);
|
||||||
|
MB2WC(buf.data(), psz, nLen + 1); // with the trailing NUL
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return wxWCharBuffer((wchar_t *) NULL);
|
wxWCharBuffer buf((wchar_t *)NULL);
|
||||||
|
|
||||||
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *pwz) const
|
const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *pwz) const
|
||||||
{
|
{
|
||||||
// return value excludes NUL
|
if ( pwz )
|
||||||
size_t nLen = pwz ? WC2MB((char *) NULL, pwz, 0) : (size_t)-1;
|
{
|
||||||
if (nLen == (size_t)-1)
|
size_t nLen = WC2MB(NULL, pwz, 0);
|
||||||
return wxCharBuffer((const char *)NULL);
|
if ( nLen != (size_t)-1 )
|
||||||
|
{
|
||||||
|
wxCharBuffer buf(nLen);
|
||||||
|
WC2MB(buf.data(), pwz, nLen + 1);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wxCharBuffer buf((char *)NULL);
|
||||||
|
|
||||||
wxCharBuffer buf(nLen); // this allocates nLen+1
|
|
||||||
WC2MB((char *)(const char *) buf, pwz, nLen+1);
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user