// Created: 29/01/98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
-// Licence: wxWindows license
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
// 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;
+ // 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;
+ }
+ else
+ {
+ // nothing to convert
+ nLen = 0;
+ }
- // nLength is number of *Unicode* characters here!
- if ((nLen != (size_t)-1) && (nLen > nLength))
- nLen = nLength;
+ // anything to do?
+ if ( (nLen != 0) && (nLen != (size_t)-1) )
+ {
+ if ( !AllocBuffer(nLen) )
+ {
+ wxFAIL_MSG( _T("out of memory in wxString::wxString") );
+ return;
+ }
- // empty?
- 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?)
}
- conv.MB2WC(m_pchData, psz, nLen);
- }
- else {
+
Init();
- }
}
#else // ANSI
// 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);
+ // 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;
+ }
else
- nLen = nLength;
- }
+ {
+ // nothing to convert
+ nLen = 0;
+ }
- // empty?
- if ( (nLen != 0) && (nLen != (size_t)-1) ) {
- if ( !AllocBuffer(nLen) ) {
- wxFAIL_MSG( _T("out of memory in wxString::wxString") );
- return;
+ // 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?)
}
- conv.WC2MB(m_pchData, pwz, nLen);
- }
- else {
+
Init();
- }
}
#endif // wxUSE_WCHAR_T
// ---------------------------------------------------------------------------
// add something to this string
-bool wxString::ConcatSelf(int nSrcLen, const wxChar *pszSrcData)
+bool wxString::ConcatSelf(size_t nSrcLen, const wxChar *pszSrcData)
{
STATISTICS_ADD(SummandLength, nSrcLen);
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
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
static bool gs_sortAscending = TRUE;
// function which is called by quick sort
-extern "C" int LINKAGEMODE
+extern "C" int wxC_CALLING_CONV // LINKAGEMODE
wxStringCompareFunction(const void *first, const void *second)
{
wxString *strFirst = (wxString *)first;