From 59a5e8f3b3a103f3a27b4441b1ced9e71b67ae98 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 15 Jun 2008 17:56:05 +0000 Subject: [PATCH] Fix #684, I hope. Redid the case-insensitive Replace All algorithm to replace from a Right side into a Left side, also avoiding use of wx 1.x compatibility functions and doing proper case-insensitive compares rather than searching a lowercased string for a lowercased substring. Originally committed to SVN as r2204. --- aegisub/dialog_search_replace.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/aegisub/dialog_search_replace.cpp b/aegisub/dialog_search_replace.cpp index cdbaf7737..2cab257b6 100644 --- a/aegisub/dialog_search_replace.cpp +++ b/aegisub/dialog_search_replace.cpp @@ -480,14 +480,22 @@ void SearchReplaceEngine::ReplaceAll() { // Normal replace else { if (!Search.matchCase) { - wxString Left, Right; - int pos; - while(Text->Lower().Contains(LookFor.Lower())) { - pos = Text->Lower().Find(LookFor.Lower()); - Left = pos ? Text->Left(pos) : _T(""); - Right = Text->Mid(pos+LookFor.Len()); - *Text = Left + ReplaceWith + Right; - count++; + wxString Left, Right = *Text; + int pos = 0; + while (pos <= (int)(Right.Len() - LookFor.Len())) { + if (Right.Mid(pos, LookFor.Len()).CmpNoCase(LookFor) == 0) { + Left.Append(Right.Mid(0,pos)).Append(ReplaceWith); + Right = Right.Mid(pos+LookFor.Len()); + count++; + replaced = true; + pos = 0; + } + else { + pos++; + } + } + if (replaced) { + *Text = Left; } } else { @@ -502,7 +510,6 @@ void SearchReplaceEngine::ReplaceAll() { if (replaced) { AssDialogue *cur = grid->GetDialogue(i); cur->UpdateData(); - //cur->ParseASSTags(); } }