- 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
 
 // under OSX locale formats are defined using
 // http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
 
 // under OSX locale formats are defined using
 // http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
 // so we need a translation function, bluntly copied from the windows
 // version above and enhanced with the additional elements needed
 
 // so we need a translation function, bluntly copied from the windows
 // version above and enhanced with the additional elements needed
 
-static wxString TranslateFromUnicodeFormat( const wxString& fmt)
+static wxString TranslateFromUnicodeFormat(const wxString& fmt)
     wxString fmtWX;
 
     wxChar chLast = _T('\0');
     size_t lastCount = 0;
     wxString fmtWX;
 
     wxChar chLast = _T('\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 == fmt.end() || *p == chLast )
+            if ( p == fmt.end() )
+                break;
+
+        switch ( (*p).GetValue() )
         {
             // these characters come in groups, start counting them
             case _T('d'):
         {
             // these characters come in groups, start counting them
             case _T('d'):
                                     wxFAIL_MSG( _T("wrong number of 'H's") );
                             }
                             break;
                                     wxFAIL_MSG( _T("wrong number of 'H's") );
                             }
                             break;
                        case _T('h'):
                             switch ( lastCount )
                             {
                        case _T('h'):
                             switch ( lastCount )
                             {
                                     wxFAIL_MSG( _T("wrong number of 'm's") );
                             }
                             break;
                                     wxFAIL_MSG( _T("wrong number of 'm's") );
                             }
                             break;
                        case _T('s'):
                             switch ( lastCount )
                             {
                        case _T('s'):
                             switch ( lastCount )
                             {
                                     wxFAIL_MSG( _T("wrong number of 's's") );
                             }
                             break;
                                     wxFAIL_MSG( _T("wrong number of 's's") );
                             }
                             break;
                         case _T('g'):
                             // strftime() doesn't have era string,
                             // ignore this format
                         case _T('g'):
                             // strftime() doesn't have era string,
                             // ignore this format
 
                 // not a special character so must be just a separator,
                 // treat as is
 
                 // not a special character so must be just a separator,
                 // treat as is
-                    if ( *p == _T('%') )
-                    {
-                        // this one needs to be escaped
-                        fmtWX += _T('%');
-                    }
-
-                    fmtWX += *p;
+                    // this one needs to be escaped
+                    fmtWX += _T('%');
-        if ( *p == _T('\0') )
-            break;
 static wxString GetLocaleDateFormat()
 {
     wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
 static wxString GetLocaleDateFormat()
 {
     wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
     wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
         (NULL, currentLocale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle));
     wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
     wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
         (NULL, currentLocale, kCFDateFormatterShortStyle, kCFDateFormatterNoStyle));
     wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
 static wxString GetLocaleFullDateFormat()
 {
     wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
 static wxString GetLocaleFullDateFormat()
 {
     wxCFRef<CFLocaleRef> currentLocale( CFLocaleCopyCurrent() );
     wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
         (NULL, currentLocale, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle));
     wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
     wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
         (NULL, currentLocale, kCFDateFormatterLongStyle, kCFDateFormatterMediumStyle));
     wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
                         if ( !hasValidDate )
 #endif // __WXOSX__
                         {
                         if ( !hasValidDate )
 #endif // __WXOSX__
                         {
                         dt = ParseFormatAt(input, end,
                                            fmtDate, fmtDateAlt);
                     Tm tm;
                         dt = ParseFormatAt(input, end,
                                            fmtDate, fmtDateAlt);
                     Tm tm;
                     if ( !dt.IsValid() )
                     {
                         wxString fmtDateLong = fmtDate;
                         wxString fmtDateLongAlt = fmtDateAlt;
                     if ( !dt.IsValid() )
                     {
                         wxString fmtDateLong = fmtDate;
                         wxString fmtDateLongAlt = fmtDateAlt;
 
                         if ( !fmtDateLong.empty() )
                         {
 
                         if ( !fmtDateLong.empty() )
                         {
                                            fmtDateLong, fmtDateLongAlt);
                             if ( !dtLong.IsValid() )
                                 return false;
                                            fmtDateLong, fmtDateLongAlt);
                             if ( !dtLong.IsValid() )
                                 return false;
                             tm = dtLong.GetTm();
                         }
                         else
                             tm = dtLong.GetTm();
                         }
                         else