X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b1801e0eb80854c1b96950de5c7082ec02346798..316df2f2092c93b3be74a4aada32e70bed90b510:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index e232c8a79d..b430829f06 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -48,7 +48,9 @@ #if wxUSE_UNICODE #undef wxUSE_EXPERIMENTAL_PRINTF - #define wxUSE_EXPERIMENTAL_PRINTF 1 + #ifndef wvsnprintf + #define wxUSE_EXPERIMENTAL_PRINTF 1 + #endif #endif // allocating extra space for each string consumes more memory but speeds up @@ -184,46 +186,6 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str) #endif //std::string compatibility -extern int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len, - const wxChar *format, va_list argptr) -{ -#if wxUSE_UNICODE - // FIXME should use wvsnprintf() or whatever if it's available - wxString s; - int iLen = s.PrintfV(format, argptr); - if ( iLen != -1 ) - { - wxStrncpy(buf, s.c_str(), len); - buf[len-1] = wxT('\0'); - } - - return iLen; -#else // ANSI - // vsnprintf() will not terminate the string with '\0' if there is not - // enough place, but we want the string to always be NUL terminated - int rc = wxVsnprintfA(buf, len - 1, format, argptr); - if ( rc == -1 ) - { - buf[len] = 0; - } - - return rc; -#endif // Unicode/ANSI -} - -extern int WXDLLEXPORT wxSnprintf(wxChar *buf, size_t len, - const wxChar *format, ...) -{ - va_list argptr; - va_start(argptr, format); - - int iLen = wxVsnprintf(buf, len, format, argptr); - - va_end(argptr); - - return iLen; -} - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -796,6 +758,45 @@ wxString operator+(const wxChar *psz, const wxString& str) // other common string functions // =========================================================================== +#if wxUSE_UNICODE +wxString wxString::FromAscii( char *ascii ) +{ + if (!ascii) + return wxEmptyString; + + size_t len = strlen( ascii ); + wxString res; + res.AllocBuffer( len ); + wchar_t *dest = (wchar_t*)(const wchar_t*) res.c_str(); + + for (size_t i = 0; i < len+1; i++) + dest[i] = (wchar_t) ascii[i]; + + return res; +} + +const wxCharBuffer wxString::ToAscii() const +{ + if (IsNull()) + return wxCharBuffer( (const char*)NULL ); + + size_t len = Len(); + wxCharBuffer buffer( len ); // allocates len+1 + + char *dest = (char*)(const char*) buffer; + + for (size_t i = 0; i < len+1; i++) + { + if (m_pchData[i] > 127) + dest[i] = '_'; + else + dest[i] = (char) m_pchData[i]; + } + + return buffer; +} +#endif + // --------------------------------------------------------------------------- // simple sub-string extraction // ---------------------------------------------------------------------------