- // now replace the occurrence of 1999 with the real year
- // we do this in two stages to stop the 2 digit year
- // matching any substring of the 4 digit year.
- // Any day,month hours and minutes components should be safe due
- // to ensuring the range of the years.
- wxString strYearReal, strYearReal2;
- strYearReal.Printf(_T("%04d"), yearReal);
- strYearReal2.Printf(_T("%02d"), yearReal % 100);
- str.Replace(strYear, replacement3);
- str.Replace(strYear2,replacement4);
- str.Replace(replacement3, strYearReal);
- str.Replace(replacement4, strYearReal2);
-
- // and replace back all occurrences of replacement string
- if ( wasReplaced )
- {
- str.Replace(replacement2, strYear2);
- str.Replace(replacement, strYear);
- }
+ // now replace the replacement year with the real year:
+ // notice that we have to replace the 4 digit year with
+ // a unique string not appearing in strftime() output
+ // first to prevent the 2 digit year from matching any
+ // substring of the 4 digit year (but any day, month,
+ // hours or minutes components should be safe because
+ // they are never in 70-99 range)
+ wxString replacement("|");
+ while ( str.find(replacement) != wxString::npos )
+ replacement += '|';
+
+ str.Replace(wxString::Format("%d", year),
+ replacement);
+ str.Replace(wxString::Format("%d", year % 100),
+ wxString::Format("%d", yearReal % 100));
+ str.Replace(replacement,
+ wxString::Format("%d", yearReal));