correct some compatibility problems with the existing Unicode-mode code (#9513), more remains to be done (#9560)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54060 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2008-06-09 22:50:55 +00:00
parent c1bc8d9f92
commit 425eee4164
2 changed files with 52 additions and 16 deletions

View File

@ -1088,22 +1088,39 @@ public:
// the missing (in the string) fields with the values of dateDef (by
// default, they will not change if they had valid values or will
// default to Today() otherwise)
// notice that we unfortunately need all those overloads because we use
// the type of the date string to select the return value of the
// function: it's wchar_t if a wide string is passed for compatibility
// with the code doing "const wxChar *p = dt.ParseFormat(_T("..."))",
// but char* in all other cases for compatibility with ANSI build which
// allowed code like "const char *p = dt.ParseFormat("...")"
//
// so we need wchar_t overload and now passing s.c_str() as first
// argument is ambiguous because it's convertible to both wxString and
// wchar_t* and now it's passing char* which becomes ambiguous as it is
// convertible to both wxString and wxCStrData hence we need char*
// overload too
//
// and to make our life more miserable we also pay for having the
// optional dateDef parameter: as it's almost never used, we want to
// allow people to omit it when specifying the end iterator output
// parameter but we still have to allow specifying dateDef too, so we
// need another overload for this
//
// FIXME: all this mess could be avoided by using some class similar to
// wxFormatString, i.e. remembering string [pointer] of any type
// and convertible to either char* or wchar_t* as wxCStrData and
// having only 1 (or 2, because of the last paragraph above)
// overload taking it, see #9560
const char *ParseFormat(const wxString& date,
const wxString& format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime,
wxString::const_iterator *end = NULL);
const char *ParseFormat(const wxString& date,
const char *format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime,
wxString::const_iterator *end = NULL)
{
return ParseFormat(date, wxString(format), dateDef, end);
}
const char *ParseFormat(const wxString& date,
const wxString& format = wxDefaultDateTimeFormat,
wxString::const_iterator *end = NULL)
const wxString& format,
wxString::const_iterator *end)
{
return ParseFormat(date, format, wxDefaultDateTime, end);
}
@ -1135,12 +1152,6 @@ public:
return ParseFormat(wxString(date), format, dateDef);
}
const char *ParseFormat(const char *date,
const char *format = wxDefaultDateTimeFormat,
const wxDateTime& dateDef = wxDefaultDateTime)
{
return ParseFormat(wxString(date), wxString(format), dateDef);
}
// parse a string containing date, time or both in ISO 8601 format
//

View File

@ -684,6 +684,31 @@ void DateTimeTestCase::TestTimeFormat()
}
}
}
// test compilation of some calls which should compile (and not result in
// ambiguity because of char*<->wxCStrData<->wxString conversions)
wxDateTime dt;
wxString s("foo");
CPPUNIT_ASSERT( !dt.ParseFormat("foo") );
CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo")) );
CPPUNIT_ASSERT( !dt.ParseFormat(s) );
CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str()) );
CPPUNIT_ASSERT( !dt.ParseFormat("foo", "%c") );
CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), "%c") );
CPPUNIT_ASSERT( !dt.ParseFormat(s, "%c") );
CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), "%c") );
CPPUNIT_ASSERT( !dt.ParseFormat("foo", wxT("%c")) );
CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), wxT("%c")) );
CPPUNIT_ASSERT( !dt.ParseFormat(s, "%c") );
CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), wxT("%c")) );
wxString spec("%c");
CPPUNIT_ASSERT( !dt.ParseFormat("foo", spec) );
CPPUNIT_ASSERT( !dt.ParseFormat(wxT("foo"), spec) );
CPPUNIT_ASSERT( !dt.ParseFormat(s, spec) );
CPPUNIT_ASSERT( !dt.ParseFormat(s.c_str(), spec) );
}
void DateTimeTestCase::TestTimeSpanFormat()