[gnome-subtitles] Fixed bug #628427 - crash when searching backwards



commit 1d6e58367398bd6d5af32ed38d9b7c2dbc643f91
Author: Pedro Castro <mail pedrocastro org>
Date:   Thu Sep 9 21:53:30 2010 +0100

    Fixed bug #628427 - crash when searching backwards
    
    Don't use Regex.Match(string, int32, int32) when searching backwards as this
    method behaves differently with mono libraries version 2.6.x

 src/SubLib/Core/Search/SearchOperator.cs |   25 ++++++++++++++++---------
 1 files changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/src/SubLib/Core/Search/SearchOperator.cs b/src/SubLib/Core/Search/SearchOperator.cs
index 327900e..b8e61c4 100644
--- a/src/SubLib/Core/Search/SearchOperator.cs
+++ b/src/SubLib/Core/Search/SearchOperator.cs
@@ -324,25 +324,32 @@ public class SearchOperator {
 	
 	private SubtitleSearchResults FindInTextContent (int subtitleNumber, string lineBreak, Regex regex, SubtitleTextType textType) {
 		SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType);
-		return MatchValues(regex.Match(text.Get(lineBreak)), subtitleNumber, textType);
+		return MatchValues(regex.Match(text.Get(lineBreak)), subtitleNumber, textType, 0);
 	}
 	
 	private SubtitleSearchResults FindInTextContentFromIndex (int subtitleNumber, string lineBreak, Regex regex, int startIndex, SubtitleTextType textType) {
 		SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType);
-		return MatchValues(regex.Match(text.Get(lineBreak), startIndex), subtitleNumber, textType);
+		return MatchValues(regex.Match(text.Get(lineBreak), startIndex), subtitleNumber, textType, 0);
 	}
 	
 	private SubtitleSearchResults FindInTextContentTillIndex (int subtitleNumber, string lineBreak, Regex regex, int endIndex, SubtitleTextType textType, bool backwards) {
 		SubtitleText text = subtitles.GetSubtitleText(subtitleNumber, textType);
-		string matchText = text.Get(lineBreak);
-		int startIndex = (backwards ? matchText.Length : 0);
-		int length = (backwards ? matchText.Length - endIndex : endIndex);		
-		return MatchValues(regex.Match(text.Get(lineBreak), startIndex, length), subtitleNumber, textType);
+		string subtitleText = text.Get(lineBreak);
+
+		if (backwards) {
+			string subtitleTextSubstring = subtitleText.Substring(endIndex);
+			return MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, endIndex);
+		}
+		else {
+			string subtitleTextSubstring = subtitleText.Substring(0, endIndex);
+			return MatchValues(regex.Match(subtitleTextSubstring), subtitleNumber, textType, 0);
+		}
 	}
 	
-	private SubtitleSearchResults MatchValues (Match match, int subtitleNumber, SubtitleTextType textType) {
-		if (match.Success)
-			return new SubtitleSearchResults(subtitleNumber, textType, match.Index, match.Length);
+	private SubtitleSearchResults MatchValues (Match match, int subtitleNumber, SubtitleTextType textType, int charsBeforeMatchInput) {
+		if (match.Success) {
+			return new SubtitleSearchResults(subtitleNumber, textType, match.Index + charsBeforeMatchInput, match.Length);
+		}
 		else
 			return null;
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]