#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
#endif //std::string compatibility
-extern int WXDLLEXPORT wxVsnprintf(wxChar *buf, size_t len,
- const wxChar *format, va_list argptr)
+#ifndef wxVsnprintf
+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 )
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
-extern int WXDLLEXPORT wxSnprintf(wxChar *buf, size_t len,
- const wxChar *format, ...)
+#ifndef wxSnprintf
+int WXDLLEXPORT wxSnprintf(wxChar *buf, size_t len,
+ const wxChar *format, ...)
{
va_list argptr;
va_start(argptr, format);
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
// 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
// ---------------------------------------------------------------------------