merged 2.4 branch into the trunk
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18040 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -229,24 +229,38 @@ wxString::wxString(const void *pStart, const void *pEnd)
|
||||
// from multibyte string
|
||||
wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
|
||||
{
|
||||
// first get necessary size
|
||||
size_t nLen = psz ? conv.MB2WC((wchar_t *) NULL, psz, 0) : 0;
|
||||
|
||||
// nLength is number of *Unicode* characters here!
|
||||
if ((nLen != (size_t)-1) && (nLen > nLength))
|
||||
nLen = nLength;
|
||||
|
||||
// empty?
|
||||
if ( (nLen != 0) && (nLen != (size_t)-1) ) {
|
||||
if ( !AllocBuffer(nLen) ) {
|
||||
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
|
||||
return;
|
||||
// first get the size of the buffer we need
|
||||
size_t nLen;
|
||||
if ( psz )
|
||||
{
|
||||
// calculate the needed size ourselves or use a provide one
|
||||
nLen = nLength == wxSTRING_MAXLEN ? conv.MB2WC(NULL, psz, 0) : nLength;
|
||||
}
|
||||
conv.MB2WC(m_pchData, psz, nLen);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// nothing to convert
|
||||
nLen = 0;
|
||||
}
|
||||
|
||||
// anything to do?
|
||||
if ( (nLen != 0) && (nLen != (size_t)-1) )
|
||||
{
|
||||
if ( !AllocBuffer(nLen) )
|
||||
{
|
||||
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
|
||||
return;
|
||||
}
|
||||
|
||||
// MB2WC wants the buffer size, not the string length
|
||||
if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 )
|
||||
{
|
||||
// initialized ok
|
||||
return;
|
||||
}
|
||||
//else: the conversion failed -- leave the string empty (what else?)
|
||||
}
|
||||
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
#else // ANSI
|
||||
@@ -255,27 +269,38 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
|
||||
// from wide string
|
||||
wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength)
|
||||
{
|
||||
// first get necessary size
|
||||
size_t nLen = 0;
|
||||
if (pwz)
|
||||
{
|
||||
if (nLength == wxSTRING_MAXLEN)
|
||||
nLen = conv.WC2MB((char *) NULL, pwz, 0);
|
||||
else
|
||||
nLen = nLength;
|
||||
}
|
||||
|
||||
// empty?
|
||||
if ( (nLen != 0) && (nLen != (size_t)-1) ) {
|
||||
if ( !AllocBuffer(nLen) ) {
|
||||
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
|
||||
return;
|
||||
// first get the size of the buffer we need
|
||||
size_t nLen;
|
||||
if ( pwz )
|
||||
{
|
||||
// calculate the needed size ourselves or use a provide one
|
||||
nLen = nLength == wxSTRING_MAXLEN ? conv.WC2MB(NULL, pwz, 0) : nLength;
|
||||
}
|
||||
conv.WC2MB(m_pchData, pwz, nLen);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
// nothing to convert
|
||||
nLen = 0;
|
||||
}
|
||||
|
||||
// anything to do?
|
||||
if ( (nLen != 0) && (nLen != (size_t)-1) )
|
||||
{
|
||||
if ( !AllocBuffer(nLen) )
|
||||
{
|
||||
wxFAIL_MSG( _T("out of memory in wxString::wxString") );
|
||||
return;
|
||||
}
|
||||
|
||||
// WC2MB wants the buffer size, not the string length
|
||||
if ( conv.WC2MB(m_pchData, pwz, nLen + 1) != (size_t)-1 )
|
||||
{
|
||||
// initialized ok
|
||||
return;
|
||||
}
|
||||
//else: the conversion failed -- leave the string empty (what else?)
|
||||
}
|
||||
|
||||
Init();
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_WCHAR_T
|
||||
|
||||
@@ -730,6 +755,16 @@ wxString wxString::FromAscii(const char *ascii)
|
||||
return res;
|
||||
}
|
||||
|
||||
wxString wxString::FromAscii(const char ascii)
|
||||
{
|
||||
// What do we do with '\0' ?
|
||||
|
||||
wxString res;
|
||||
res += (wchar_t)(unsigned char) ascii;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
const wxCharBuffer wxString::ToAscii() const
|
||||
{
|
||||
// this will allocate enough space for the terminating NUL too
|
||||
@@ -1752,7 +1787,7 @@ void wxArrayString::Copy(const wxArrayString& src)
|
||||
void wxArrayString::Grow(size_t nIncrement)
|
||||
{
|
||||
// only do it if no more place
|
||||
if ( m_nCount == m_nSize ) {
|
||||
if ( (m_nSize - m_nCount) < nIncrement ) {
|
||||
// if ARRAY_DEFAULT_INITIAL_SIZE were set to 0, the initially empty would
|
||||
// be never resized!
|
||||
#if ARRAY_DEFAULT_INITIAL_SIZE == 0
|
||||
|
Reference in New Issue
Block a user