compilation fix for Unicode

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20401 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-05-01 00:48:58 +00:00
parent cf5e94bc6d
commit 2423ef22ee

View File

@@ -88,7 +88,8 @@ const long wxDateTime::TIME_T_FACTOR = 1000l;
// conditional compilation // conditional compilation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#if defined(HAVE_STRPTIME) && defined(__LINUX__) #if defined(HAVE_STRPTIME) && defined(__GLIBC__) && \
((__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0))
// glibc 2.0.7 strptime() is broken - the following snippet causes it to // glibc 2.0.7 strptime() is broken - the following snippet causes it to
// crash (instead of just failing): // crash (instead of just failing):
// //
@@ -342,7 +343,7 @@ static long GetTruncatedJDN(wxDateTime::wxDateTime_t day,
- JDN_OFFSET; - JDN_OFFSET;
} }
// this function is a wrapper around strftime(3) // this function is a wrapper around strftime(3) adding error checking
static wxString CallStrftime(const wxChar *format, const tm* tm) static wxString CallStrftime(const wxChar *format, const tm* tm)
{ {
wxChar buf[4096]; wxChar buf[4096];
@@ -355,6 +356,35 @@ static wxString CallStrftime(const wxChar *format, const tm* tm)
return wxString(buf); return wxString(buf);
} }
#ifdef HAVE_STRPTIME
// Unicode-friendly strptime() wrapper
static const wxChar *
CallStrptime(const wxChar *input, const char *fmt, tm *tm)
{
// the problem here is that strptime() returns pointer into the string we
// passed to it while we're really interested in the pointer into the
// original, Unicode, string so we try to transform the pointer back
#if wxUSE_UNICODE
wxCharBuffer inputMB(wxConvertWX2MB(input));
#else // ASCII
const char * const inputMB = input;
#endif // Unicode/Ascii
const char *result = strptime(inputMB, fmt, tm);
if ( !result )
return NULL;
#if wxUSE_UNICODE
// FIXME: this is wrong in presence of surrogates &c
return input + (result - inputMB.data());
#else // ASCII
return result;
#endif // Unicode/Ascii
}
#endif // HAVE_STRPTIME
// if year and/or month have invalid values, replace them with the current ones // if year and/or month have invalid values, replace them with the current ones
static void ReplaceDefaultYearMonthWithCurrent(int *year, static void ReplaceDefaultYearMonthWithCurrent(int *year,
wxDateTime::Month *month) wxDateTime::Month *month)
@@ -2921,12 +2951,13 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
case _T('x'): // locale default date representation case _T('x'): // locale default date representation
#ifdef HAVE_STRPTIME #ifdef HAVE_STRPTIME
// try using strptime() - it may fail even if the input is // try using strptime() -- it may fail even if the input is
// correct but the date is out of range, so we will fall back // correct but the date is out of range, so we will fall back
// to our generic code anyhow (FIXME !Unicode friendly) // to our generic code anyhow
{ {
struct tm tm; struct tm tm;
const wxChar *result = strptime(input, "%x", &tm);
const wxChar *result = CallStrptime(input, "%x", &tm);
if ( result ) if ( result )
{ {
input = result; input = result;
@@ -2991,7 +3022,7 @@ const wxChar *wxDateTime::ParseFormat(const wxChar *date,
{ {
// use strptime() to do it for us (FIXME !Unicode friendly) // use strptime() to do it for us (FIXME !Unicode friendly)
struct tm tm; struct tm tm;
input = strptime(input, "%X", &tm); input = CallStrptime(input, "%X", &tm);
if ( !input ) if ( !input )
{ {
return (wxChar *)NULL; return (wxChar *)NULL;