From 7b98e2e2f2436ea69138fb30927b77debdc31be8 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Fri, 17 Apr 2020 08:33:13 +0200 Subject: [PATCH] Fix switch of end chars in OCR-fix - thx moob :) Fix #4119 --- libse/Dictionaries/OcrFixReplaceList.cs | 41 +++++++------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/libse/Dictionaries/OcrFixReplaceList.cs b/libse/Dictionaries/OcrFixReplaceList.cs index b2a190331..e79c197ea 100644 --- a/libse/Dictionaries/OcrFixReplaceList.cs +++ b/libse/Dictionaries/OcrFixReplaceList.cs @@ -431,7 +431,6 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries pre += Environment.NewLine; word = word.Substring(2); } - while (word.Length > 1 && word[0] == '-') { pre += "-"; @@ -457,46 +456,28 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries pre += ""; word = word.Remove(0, 3); } - while (word.Length > 2 && word.EndsWith(Environment.NewLine, StringComparison.Ordinal)) + + while (word.Length > Environment.NewLine.Length && word.EndsWith(Environment.NewLine, StringComparison.Ordinal)) { - post += Environment.NewLine; - word = word.Substring(0, word.Length - 2); + post = Environment.NewLine + post; + word = word.Substring(0, word.Length - Environment.NewLine.Length); } - while (word.Length > 1 && word.EndsWith('"')) + if (word.EndsWith("", StringComparison.Ordinal)) { - post = post + "\""; - word = word.Substring(0, word.Length - 1); + post = "" + post; + word = word.Remove(word.Length - 4, 4); } - while (word.Length > 1 && word.EndsWith('.')) + while (word.Length > 1 && "\".,!?)]:;".Contains(word[word.Length - 1])) { - post = post + "."; - word = word.Substring(0, word.Length - 1); - } - while (word.EndsWith(',') && word.Length > 1) - { - post = post + ","; - word = word.Substring(0, word.Length - 1); - } - while (word.EndsWith('?') && word.Length > 1) - { - post = post + "?"; - word = word.Substring(0, word.Length - 1); - } - while (word.EndsWith('!') && word.Length > 1) - { - post = post + "!"; - word = word.Substring(0, word.Length - 1); - } - while (word.EndsWith(')') && word.Length > 1) - { - post = post + ")"; + post = word[word.Length - 1] + post; word = word.Substring(0, word.Length - 1); } if (word.EndsWith("", StringComparison.Ordinal)) { - post = post + ""; + post = "" + post; word = word.Remove(word.Length - 4, 4); } + string preWordPost = pre + word + post; if (word.Length == 0) {