// precision?
if ( *format == _T('.') )
{
- SkipDigits(&format);
+ CopyFmtChar(*format++);
+ if ( *format == _T('*') )
+ CopyFmtChar(*format++);
+ else
+ SkipDigits(&format);
}
// next we can have a size modifier
case _T('c'):
case _T('s'):
// %c -> %lc but %hc stays %hc and %lc is still %lc
- switch ( size )
- {
- case Default:
- InsertFmtChar(_T('l'));
- break;
-
- case Short:
- CopyFmtChar(_T('h'));
- break;
-
- case Long:
- ;
- }
+ if ( size == Default)
+ InsertFmtChar(_T('l'));
// fall through
default:
// nothing special to do
+ if ( size != Default )
+ CopyFmtChar(*(format - 1));
CopyFmtChar(*format++);
}
}
#define wxFormatConverter(x) (x)
#endif // wxNEED_PRINTF_CONVERSION/!wxNEED_PRINTF_CONVERSION
+#ifdef __WXDEBUG__
+// For testing the format converter
+wxString wxConvertFormat(const wxChar *format)
+{
+ return wxString(wxFormatConverter(format));
+}
+#endif
+
// ----------------------------------------------------------------------------
// wxPrintf(), wxScanf() and relatives
// ----------------------------------------------------------------------------
--- /dev/null
+#!/usr/bin/perl -w
+#
+# Prints test formats for wxFormatConverter. The output is in two columns (tab
+# separated), the first is the test input and the second is the expected
+# output.
+#
+# run the output thought formattest like this:
+# ./formats.pl | ./formattest
+#
+use strict;
+
+my %transform = (
+ s => [ 'l', 's' ],
+ S => [ '', 's' ],
+ hS => [ '', 's' ],
+ lS => [ 'l', 's' ],
+ c => [ 'l', 'c' ],
+ C => [ '', 'c' ],
+ hC => [ '', 'c' ],
+ lC => [ 'l', 'c' ]
+);
+
+print "%%\t%%\n";
+
+for my $type ('d', 's', 'S', 'c', 'C')
+{
+ for my $mod ('', 'h', 'l', 'hh', 'll', 'j') #, 'z', 't', 'L')
+ {
+ for my $prec ('', '.*', '.10')
+ {
+ for my $width ('', '*', '10')
+ {
+ for my $flag ('', '#') #, '0', '-', ' ', '+' )
+ {
+ my ($newmod, $newtype) = ($mod, $type);
+
+ if ($transform{$mod.$type}) {
+ ($newmod, $newtype) = @{$transform{$mod.$type}};
+ }
+
+ print "%$flag$width$prec$mod$type\t".
+ "%$flag$width$prec$newmod$newtype\n";
+ }
+ }
+ }
+ }
+}
--- /dev/null
+#!/usr/bin/perl -w
+#
+# Creates longer test formats for wxFormatConverter, containing two '%'s. The
+# output is basically the cross product of the output of two './formats.pl's.
+#
+# ./formats2.pl | ./formattest
+#
+use strict;
+
+open IN, './formats.pl |';
+
+while (<IN>) {
+ chomp;
+ my ($format, $expected) = split "\t";
+ open IN2, './formats.pl |';
+
+ while (<IN2>) {
+ chomp;
+ my ($format2, $expected2) = split "\t";
+ print "$format $format2\t$expected $expected2\n";
+ }
+
+ close IN2;
+}
+
+close IN;
--- /dev/null
+/*
+ * Tester for wxFormatConverter, by M. J. Wetherell
+ *
+ * Reads stdin, expects two column input (as produced by formats.pl or
+ * formats2.pl), the first column contains the test pattern, the second
+ * the expected result.
+ *
+ * The output is any patterns that wxFormatConveter doesn't transform to the
+ * expected value, in three columns: input, expected, output.
+ *
+ * ./formats.pl | ./formattest
+ * ./formats2.pl | ./formattest
+ */
+
+#include <wx/wx.h>
+#include <wx/wfstream.h>
+#include <wx/txtstrm.h>
+#include <iostream>
+
+/* This function is in wxchar.cpp to give access to wxFormatConverter,
+ * but only in debug mode.
+ */
+
+#ifdef __WXDEBUG__
+extern wxString wxConvertFormat(const wxChar *format);
+#endif
+
+class TestApp : public wxAppConsole
+{
+public:
+ int OnRun();
+};
+
+IMPLEMENT_APP_CONSOLE(TestApp)
+
+int TestApp::OnRun()
+{
+#ifdef __WXDEBUG__
+ wxFFileInputStream in(stdin);
+ wxTextInputStream txt(in, _T("\t"));
+
+ for (;;) {
+ wxString format = txt.ReadWord();
+ wxString expected = txt.ReadWord();
+ if (!in) break;
+ wxString converted = wxConvertFormat(format);
+
+ if (converted != expected)
+ std::cout << "'" << format.mb_str() << "'\t"
+ << "'" << expected.mb_str() << "'\t"
+ << "'" << converted.mb_str() << "'\n";
+ }
+#else
+ std::cout << "Please compile this test program in debug mode.\n";
+#endif
+ return 0;
+}
+
--- /dev/null
+
+Tests for wxFormatConverter by M. J. Wetherell
+
+The Perl scripts generate test patterns;
+formattest.cpp reads this file and checks
+the converted pattern matches the expected
+pattern.
+