mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-23 03:33:18 +01:00
"Fix missing spaces" bug fixed (e.g. being noisy again.Shush them. >being noisy again. Shush them.)
This commit is contained in:
parent
48f7bc0afd
commit
f84b3e1105
@ -56,7 +56,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
private bool _hasFixesBeenMade;
|
||||
|
||||
static readonly Regex FixMissingSpacesReComma = new Regex(@"[^\s\d],[^\s]", RegexOptions.Compiled);
|
||||
static readonly Regex FixMissingSpacesRePeriod = new Regex(@"[a-z][.][a-zA-Z]", RegexOptions.Compiled);
|
||||
static readonly Regex FixMissingSpacesRePeriod = new Regex(@"[a-z][a-z][.][a-zA-Z]", RegexOptions.Compiled);
|
||||
static readonly Regex FixMissingSpacesReQuestionMark = new Regex(@"[^\s\d]\?[a-zA-Z]", RegexOptions.Compiled);
|
||||
static readonly Regex FixMissingSpacesReExclamation = new Regex(@"[^\s\d]\![a-zA-Z]", RegexOptions.Compiled);
|
||||
static readonly Regex FixMissingSpacesReColon = new Regex(@"[^\s\d]\:[a-zA-Z]", RegexOptions.Compiled);
|
||||
@ -1445,9 +1445,11 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
{
|
||||
bool isMatchAbbreviation = false;
|
||||
|
||||
string word = GetWordFromIndex(p.Text, match.Index);
|
||||
word = RemoveEverySecondLetter(word, 1);
|
||||
if (!word.Contains("."))
|
||||
string word = GetWordFromIndex(p.Text, match.Index);
|
||||
if (Utilities.CountTagInText(word, '.') > 1)
|
||||
isMatchAbbreviation = true;
|
||||
|
||||
if (!isMatchAbbreviation && word.Contains("@")) // skip emails
|
||||
isMatchAbbreviation = true;
|
||||
|
||||
if (match.Value.ToLower() == "h.d" && match.Index > 0 && p.Text.Substring(match.Index - 1, 4).ToLower() == "ph.d")
|
||||
@ -1459,7 +1461,7 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
missingSpaces++;
|
||||
|
||||
string oldText = p.Text;
|
||||
p.Text = p.Text.Replace(match.Value, match.Value[0] + ". " + match.Value[match.Value.Length - 1]);
|
||||
p.Text = p.Text.Replace(match.Value, match.Value.Replace(".", ". "));
|
||||
AddFixToListView(p, fixAction, oldText, p.Text);
|
||||
}
|
||||
}
|
||||
@ -1663,17 +1665,6 @@ namespace Nikse.SubtitleEdit.Forms
|
||||
LogStatus(_language.FixMissingSpaces, string.Format(_language.XMissingSpacesAdded, missingSpaces));
|
||||
}
|
||||
|
||||
private static string RemoveEverySecondLetter(string text, int start)
|
||||
{
|
||||
int i = start;
|
||||
while (i < text.Length)
|
||||
{
|
||||
text = text.Remove(i, 1);
|
||||
i++;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
private static string GetWordFromIndex(string text, int index)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || index < 0 || index >= text.Length)
|
||||
|
@ -2491,6 +2491,20 @@ namespace Nikse.SubtitleEdit.Logic
|
||||
return count;
|
||||
}
|
||||
|
||||
public static int CountTagInText(string text, char tag)
|
||||
{
|
||||
int count = 0;
|
||||
int index = text.IndexOf(tag);
|
||||
while (index >= 0)
|
||||
{
|
||||
count++;
|
||||
if (index == text.Length)
|
||||
return count;
|
||||
index = text.IndexOf(tag, index + 1);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static string FixInvalidItalicTags(string text)
|
||||
{
|
||||
const string beginTag = "<i>";
|
||||
|
@ -482,6 +482,66 @@ namespace Test
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesBeforePeriod1()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "It will be okay.It surely will be!");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "It will be okay. It surely will be!");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesBeforePeriod2()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "you can't get out.Alright?");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "you can't get out. Alright?");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesNoChange1()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "What did Dr. Gey say?");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "What did Dr. Gey say?");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesNoChange2()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "Go to the O.R. now!");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Go to the O.R. now!");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesNoChange3()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "Email niksedk@gmail.Com now!");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Email niksedk@gmail.Com now!");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DeploymentItem("SubtitleEdit.exe")]
|
||||
public void FixMissingSpacesNoChange4()
|
||||
{
|
||||
var target = GetFixCommonErrorsLib();
|
||||
InitializeFixCommonErrorsLine(target, "Go to www.Nikse.Dk for more info");
|
||||
target.FixMissingSpaces();
|
||||
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Go to www.Nikse.Dk for more info");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Start with uppercase after paragraph
|
||||
|
Loading…
Reference in New Issue
Block a user