minor corrections to TranslateFromUnicodeFormat()
- Don't try to dereference end() iteratorm this will fail (unlike comparing pointer with NUL) - Use prefix rather than postfix increment for iterator - Use wxUniChar::GetValue() rather than cast to char for consistency with other switch statements in the same file git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59880 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1067,26 +1067,28 @@ static wxString GetLocaleDateFormat()
|
|||||||
|
|
||||||
// under OSX locale formats are defined using
|
// under OSX locale formats are defined using
|
||||||
// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
// http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
|
||||||
//
|
//
|
||||||
// so we need a translation function, bluntly copied from the windows
|
// so we need a translation function, bluntly copied from the windows
|
||||||
// version above and enhanced with the additional elements needed
|
// version above and enhanced with the additional elements needed
|
||||||
|
|
||||||
static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
static wxString TranslateFromUnicodeFormat(const wxString& fmt)
|
||||||
{
|
{
|
||||||
|
|
||||||
wxString fmtWX;
|
wxString fmtWX;
|
||||||
|
|
||||||
wxChar chLast = _T('\0');
|
wxChar chLast = _T('\0');
|
||||||
size_t lastCount = 0;
|
size_t lastCount = 0;
|
||||||
for ( wxString::const_iterator p = fmt.begin(); /* NUL handled inside */; p++ )
|
for ( wxString::const_iterator p = fmt.begin(); /* end handled inside */; ++p )
|
||||||
{
|
{
|
||||||
if ( *p == chLast )
|
if ( p == fmt.end() || *p == chLast )
|
||||||
{
|
{
|
||||||
lastCount++;
|
lastCount++;
|
||||||
|
if ( p == fmt.end() )
|
||||||
|
break;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( (char) *p )
|
switch ( (*p).GetValue() )
|
||||||
{
|
{
|
||||||
// these characters come in groups, start counting them
|
// these characters come in groups, start counting them
|
||||||
case _T('d'):
|
case _T('d'):
|
||||||
@@ -1182,7 +1184,7 @@ static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
|||||||
wxFAIL_MSG( _T("wrong number of 'H's") );
|
wxFAIL_MSG( _T("wrong number of 'H's") );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('h'):
|
case _T('h'):
|
||||||
switch ( lastCount )
|
switch ( lastCount )
|
||||||
{
|
{
|
||||||
@@ -1208,7 +1210,7 @@ static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
|||||||
wxFAIL_MSG( _T("wrong number of 'm's") );
|
wxFAIL_MSG( _T("wrong number of 'm's") );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('s'):
|
case _T('s'):
|
||||||
switch ( lastCount )
|
switch ( lastCount )
|
||||||
{
|
{
|
||||||
@@ -1221,7 +1223,7 @@ static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
|||||||
wxFAIL_MSG( _T("wrong number of 's's") );
|
wxFAIL_MSG( _T("wrong number of 's's") );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case _T('g'):
|
case _T('g'):
|
||||||
// strftime() doesn't have era string,
|
// strftime() doesn't have era string,
|
||||||
// ignore this format
|
// ignore this format
|
||||||
@@ -1239,20 +1241,14 @@ static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
|||||||
|
|
||||||
// not a special character so must be just a separator,
|
// not a special character so must be just a separator,
|
||||||
// treat as is
|
// treat as is
|
||||||
if ( *p != _T('\0') )
|
if ( *p == _T('%') )
|
||||||
{
|
{
|
||||||
if ( *p == _T('%') )
|
// this one needs to be escaped
|
||||||
{
|
fmtWX += _T('%');
|
||||||
// this one needs to be escaped
|
|
||||||
fmtWX += _T('%');
|
|
||||||
}
|
|
||||||
|
|
||||||
fmtWX += *p;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( *p == _T('\0') )
|
fmtWX += *p;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmtWX;
|
return fmtWX;
|
||||||
@@ -1261,7 +1257,7 @@ static wxString TranslateFromUnicodeFormat( const wxString& fmt)
|
|||||||
static wxString GetLocaleDateFormat()
|
static wxString GetLocaleDateFormat()
|
||||||
{
|
{
|
||||||
wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
|
wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
|
||||||
|
|
||||||
wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
|
wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
|
||||||
(NULL, currentLocale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle));
|
(NULL, currentLocale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle));
|
||||||
wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
|
wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
|
||||||
@@ -1271,7 +1267,7 @@ static wxString GetLocaleDateFormat()
|
|||||||
static wxString GetLocaleFullDateFormat()
|
static wxString GetLocaleFullDateFormat()
|
||||||
{
|
{
|
||||||
wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
|
wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
|
||||||
|
|
||||||
wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
|
wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
|
||||||
(NULL, currentLocale, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle));
|
(NULL, currentLocale, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle));
|
||||||
wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
|
wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
|
||||||
@@ -1461,7 +1457,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
|||||||
hasValidDate = true;
|
hasValidDate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !hasValidDate )
|
if ( !hasValidDate )
|
||||||
#endif // __WXOSX__
|
#endif // __WXOSX__
|
||||||
{
|
{
|
||||||
@@ -1726,12 +1722,12 @@ wxDateTime::ParseFormat(const wxString& date,
|
|||||||
dt = ParseFormatAt(input, end,
|
dt = ParseFormatAt(input, end,
|
||||||
fmtDate, fmtDateAlt);
|
fmtDate, fmtDateAlt);
|
||||||
Tm tm;
|
Tm tm;
|
||||||
|
|
||||||
if ( !dt.IsValid() )
|
if ( !dt.IsValid() )
|
||||||
{
|
{
|
||||||
wxString fmtDateLong = fmtDate;
|
wxString fmtDateLong = fmtDate;
|
||||||
wxString fmtDateLongAlt = fmtDateAlt;
|
wxString fmtDateLongAlt = fmtDateAlt;
|
||||||
|
|
||||||
|
|
||||||
if ( !fmtDateLong.empty() )
|
if ( !fmtDateLong.empty() )
|
||||||
{
|
{
|
||||||
@@ -1741,7 +1737,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
|||||||
fmtDateLong, fmtDateLongAlt);
|
fmtDateLong, fmtDateLongAlt);
|
||||||
if ( !dtLong.IsValid() )
|
if ( !dtLong.IsValid() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
tm = dtLong.GetTm();
|
tm = dtLong.GetTm();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user