]> git.saurik.com Git - wxWidgets.git/commitdiff
%s to %ls conversion
authorRobert Roebling <robert@roebling.de>
Sat, 17 Aug 2002 12:11:03 +0000 (12:11 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 17 Aug 2002 12:11:03 +0000 (12:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16566 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/filefn.cpp
src/common/string.cpp
src/common/toplvcmn.cpp
src/common/wxchar.cpp

index b064624435bbd74d710393997b22f6f8f7d7d373..fd4b6b7ae9f5611d4eeaaa76d216088f2386d65f 100644 (file)
@@ -1479,8 +1479,6 @@ wxChar *wxGetWorkingDirectory(wxChar *buf, int sz)
     #if wxUSE_UNICODE
         // finally convert the result to Unicode if needed
         wxConvFile.MB2WC(buf, cbuf, sz);
-        // wxString tmp = wxString::FromAscii( cbuf );
-        // wxStrcpy( buf, tmp.c_str() );
     #endif // wxUSE_UNICODE
     }
 
index e85bcf2b6bae8affdaaaafce919b8b6778fe9fc4..b430829f0614f0ed13cde63ca829bcd992246b61 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------
index f5386f9835865f904a21eb1d0aa98b18921a2d1d..b1af3fdd14ece11311c8a76ec6b20c08d2bf198e 100644 (file)
@@ -28,9 +28,9 @@
 #endif
 
 #ifndef WX_PRECOMP
-    #include "wx/app.h"
     #include "wx/toplevel.h"
     #include "wx/dcclient.h"
+    #include "wx/app.h"
 #endif // WX_PRECOMP
 
 // ----------------------------------------------------------------------------
index 39efe204fa8026594f724032dc6b5bad6a951e59..2b4a5a90ebc34109097c5ec048bcf6a56786c138 100644 (file)
@@ -119,6 +119,265 @@ size_t   WXDLLEXPORT wcslen(const wchar_t *s)
 }
 #endif
 
+#ifdef wxNEED_PRINTF_CONVERSION
+
+#define CONVERT_FORMAT_1  \
+    wxChar *new_format = (wxChar*) format; \
+    size_t old_len = wxStrlen( format ); \
+    int n = 0; \
+    size_t i; \
+    for (i = 0; i < old_len; i++) \
+    { \
+        if ( (format[i] == L'%') && \
+             ((i < old_len) && ((format[i+1] == L's') || (format[i+1] == L'c'))) && \
+             ((i == 0) || (format[i-1] != L'%')) ) \
+        { \
+            n++; \
+        } \
+    } \
+ \
+    if (n > 0) \
+    { \
+        new_format = new wxChar[old_len+n+1]; \
+        wxChar *s = new_format; \
+ \
+        for (i = 0; i < old_len+1; i++) \
+        { \
+            if ( (format[i] == L'%') && \
+                 ((i < old_len) && ((format[i+1] == L's') || (format[i+1] == L'c'))) && \
+                 ((i == 0) || (format[i-1] != L'%')) ) \
+            { \
+                *s = L'%'; \
+                s++; \
+                *s = L'l'; \
+                s++; \
+            } \
+            else \
+            { \
+                *s = format[i]; \
+                s++; \
+            } \
+        } \
+    }
+
+#define CONVERT_FORMAT_2 \
+    if (n > 0) \
+        delete [] new_format;
+    
+
+int wxScanf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+
+    int ret = vwscanf( new_format, argptr );
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+    
+    return ret;
+}
+
+int wxSscanf( const wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+
+    int ret = vswscanf( str, new_format, argptr );
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+    
+    return ret;
+}
+
+int wxFscanf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+
+    int ret = vfwscanf(stream, new_format, argptr);
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+    
+    return ret;
+}
+
+int wxVsscanf( const wxChar *str, const wxChar *format, va_list ap )
+{
+    CONVERT_FORMAT_1
+
+    int ret = vswscanf( str, new_format, ap );
+    
+    CONVERT_FORMAT_2
+
+    return ret;
+}
+
+int wxPrintf( const wxChar *format, ... ) ATTRIBUTE_PRINTF_2
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+    
+    int ret = vwprintf( new_format, argptr );
+    
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+
+    return ret;
+}
+
+int wxSnprintf( wxChar *str, size_t size, const wxChar *format, ... ) ATTRIBUTE_PRINTF_4
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+
+    int ret = vswprintf( str, size, new_format, argptr );
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+
+    return ret;
+}
+
+int wxSprintf( wxChar *str, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start(argptr, format);
+
+    // Ugly
+    int ret = vswprintf( str, 10000, new_format, argptr );
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+
+    return ret;
+}
+
+int wxFprintf( FILE *stream, const wxChar *format, ... ) ATTRIBUTE_PRINTF_3
+{
+    CONVERT_FORMAT_1
+
+    va_list argptr;
+    va_start( argptr, format );
+
+    int ret = vfwprintf( stream, new_format, argptr );
+
+    CONVERT_FORMAT_2
+
+    va_end(argptr);
+
+    return ret;
+}
+
+int wxVfprint( FILE *stream, const wxChar *format, va_list ap )
+{
+    CONVERT_FORMAT_1
+
+    int ret = vfwprintf( stream, new_format, ap );
+
+    CONVERT_FORMAT_2
+
+    return ret;
+}
+
+int wxVprintf( const wxChar *format, va_list ap )
+{
+    CONVERT_FORMAT_1
+
+    int ret = vwprintf( new_format, ap );
+
+    CONVERT_FORMAT_2
+
+    return ret;
+}
+
+int wxVsnprintf( wxChar *str, size_t size, const wxChar *format, va_list ap )
+{
+    CONVERT_FORMAT_1
+
+    int ret = vswprintf( str, size, new_format, ap );
+
+    CONVERT_FORMAT_2
+
+    return ret;
+}
+
+int wxVsprintf( wxChar *str, const wxChar *format, va_list ap )
+{
+    CONVERT_FORMAT_1
+
+    // This is so ugly
+    int ret = vswprintf(str, 10000, new_format, ap);
+
+    CONVERT_FORMAT_2
+
+    return ret;
+}
+#endif
+
+#if !defined(wxVsnprintf) && !defined(wxHAS_VSNPRINTF)
+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
+}
+#endif
+
+#if !defined(wxSnprintf) && !defined(wxHAS_SNPRINTF)
+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;
+}
+#endif
+
 #if defined(__WIN32__) && defined(wxNEED_WX_CTYPE_H)
 inline WORD wxMSW_ctype(wxChar ch)
 {