Fix crash in "Fix common errors" part 2 - thx tormento :)

This commit is contained in:
Nikolaj Olsson 2017-11-24 19:16:52 +01:00
parent 46688866f4
commit 9fefea4bc9
2 changed files with 48 additions and 9 deletions

View File

@ -22,24 +22,33 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
Match match = ReAfterLowercaseLetter.Match(st.StrippedText);
while (match.Success)
{
if (!(match.Index > 1 && p.Text.Substring(match.Index - 1, 2) == "Mc") // irish names, McDonalds etc.
&& p.Text[match.Index + 1] == 'I'
if (!(match.Index > 1 && st.StrippedText.Substring(match.Index - 1, 2) == "Mc") // irish names, McDonalds etc.
&& st.StrippedText[match.Index + 1] == 'I'
&& callbacks.AllowFix(p, fixAction))
{
string word = GetWholeWord(st.StrippedText, match.Index);
if (!callbacks.IsName(word))
{
var old = st.StrippedText;
st.StrippedText = st.StrippedText.Substring(0, match.Index + 1) + "l";
if (match.Index + 2 < old.Length)
st.StrippedText += old.Substring(match.Index + 2);
p.Text = st.MergedString;
if (match.Index + 2 < oldText.Length)
p.Text += oldText.Substring(match.Index + 2);
st = new StrippableText(p.Text);
uppercaseIsInsideLowercaseWords++;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
match = ReAfterLowercaseLetter.Match(st.StrippedText, match.Index);
}
else
{
match = match.NextMatch();
}
}
match = match.NextMatch();
else
{
match = match.NextMatch();
}
}
match = ReBeforeLowercaseLetter.Match(st.StrippedText);
@ -116,10 +125,18 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
}
else
{
st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
p.Text = st.MergedString;
uppercaseIsInsideLowercaseWords++;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
var ok = true;
if (match.Index >= 2 && st.StrippedText.Substring(match.Index - 2, 2) == "Mc")
ok = false;
if (ok)
{
st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
p.Text = st.MergedString;
uppercaseIsInsideLowercaseWords++;
callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
}
}
}
}

View File

@ -1637,6 +1637,28 @@ namespace Test
}
}
[TestMethod]
public void FixUppercaseIInsideWords4()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>FIight DU 720 from BraziI...</i>");
new FixUppercaseIInsideWords().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Flight DU 720 from Brazil...</i>");
}
}
[TestMethod]
public void FixUppercaseIInsideWords5()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "<i>FIight DU 720 from McIvan BraziI...</i>");
new FixUppercaseIInsideWords().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual(_subtitle.Paragraphs[0].Text, "<i>Flight DU 720 from McIvan Brazil...</i>");
}
}
#endregion Fix uppercase I inside words
#region Fix dialogs on one line