X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a59c124d063b0df0b3259d99b5b569206414f8f5..316df2f2092c93b3be74a4aada32e70bed90b510:/src/common/string.cpp diff --git a/src/common/string.cpp b/src/common/string.cpp index 6956cdd521..b430829f06 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -186,74 +186,6 @@ wxSTD ostream& operator<<(wxSTD ostream& os, const wxString& str) #endif //std::string compatibility -#ifndef wxVsnprintf -int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len, - const wxChar *format, va_list argptr) -{ -#if wxUSE_UNICODE - 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 -} -#else -// GNU libc 2.2 only has for wxVsnprintf for Unicode called vswprintf -// so we imitate wxVsprintf using it. -int WXDLLEXPORT wxVsprintf(wxChar *buf, - const wxChar *format, - va_list argptr) -{ - return vswprintf( buf, 10000, format, argptr ); -} -#endif - -#ifndef wxSnprintf -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; -} -#else -// GNU libc 2.2 only has for wxSnprintf for Unicode called swprintf -// so we imitate wxSprintf using it. -int WXDLLEXPORT wxSprintf(wxChar *buf, - const wxChar *format, - ...) ATTRIBUTE_PRINTF_2 -{ - va_list argptr; - va_start(argptr, format); - - int iLen = swprintf(buf, 10000, format, argptr); - - va_end(argptr); - - return iLen; -} -#endif - // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -826,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 // ---------------------------------------------------------------------------