]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix handling of positional parameters in wxPrintf() and related.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Feb 2012 13:28:34 +0000 (13:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 6 Feb 2012 13:28:34 +0000 (13:28 +0000)
Handle positional parameter specifications in wxFormatConverter to ensure that
e.g. "%N$s" are correctly transformed to "%N$S" if needed. This fixes the use
of positional parameters under OS X.

Closes #10965.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70523 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/common/strvararg.cpp
tests/strings/strings.cpp

index 1fcd83c709735c73ccf00d61c7e027fef3599693..c4a224fb8544a02bd331ed614791f78ba5ec6429 100644 (file)
@@ -501,6 +501,7 @@ MSW:
 OSX:
 
 - Provide native implementations of wxDatePickerCtrl and wxTimePickerCtrl.
+- Fix handling of positional parameters in wxPrintf() &c (David Connet).
 
 Univ:
 
index a4c2256dfb474ac44d40fa4c977ecc5288a4d1e3..484fe0f883acf24b14e65189a09da19085e7ac15 100644 (file)
@@ -161,6 +161,19 @@ public:
         {
             if ( CopyFmtChar(*format++) == wxT('%') )
             {
+#if wxUSE_PRINTF_POS_PARAMS
+                if ( *format >= '0' && *format <= '9' )
+                {
+                    SkipDigits(&format);
+                    if ( *format == '$' )
+                    {
+                        // It was a positional argument specification.
+                        CopyFmtChar(*format++);
+                    }
+                    //else: it was a width specification, nothing else to do.
+                }
+#endif // wxUSE_PRINTF_POS_PARAMS
+
                 // skip any flags
                 while ( IsFlagChar(*format) )
                     CopyFmtChar(*format++);
index 39e1904fd6dd2189cbc709744728b5e3f5adf002..43e3640520a30d6c2acd184109ec17fdf49854ff 100644 (file)
@@ -165,6 +165,13 @@ void StringTestCase::Format()
         wxString s(wxT('Z'), len);
         CPPUNIT_ASSERT_EQUAL( len, wxString::Format(wxT("%s"), s.c_str()).length());
     }
+
+
+    CPPUNIT_ASSERT_EQUAL
+    (
+        "two one",
+        wxString::Format(wxT("%2$s %1$s"), wxT("one"), wxT("two"))
+    );
 }
 
 void StringTestCase::Constructors()