- // now replace the occurrence of 1999 with the real year
- wxString strYearReal, strYearReal2;
- strYearReal.Printf(_T("%04d"), yearReal);
- strYearReal2.Printf(_T("%02d"), yearReal % 100);
- str.Replace(strYear, strYearReal);
- str.Replace(strYear2, 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));