Fix date postfixes in "remove spaces" - thx Boulder08 :)

Fix #4129
This commit is contained in:
Nikolaj Olsson 2020-04-19 07:37:52 +02:00
parent cd4912827c
commit 3fe480d1d0
3 changed files with 43 additions and 1 deletions

View File

@ -297,6 +297,26 @@ namespace Nikse.SubtitleEdit.Core
return false;
}
public static bool ContainsNumber(this string s)
{
if (s == null)
{
return false;
}
int max = s.Length;
for (int index = 0; index < max; index++)
{
var ch = s[index];
if (char.IsNumber(ch))
{
return true;
}
}
return false;
}
public static string RemoveControlCharacters(this string s)
{
int max = s.Length;

View File

@ -2115,6 +2115,21 @@ namespace Nikse.SubtitleEdit.Core
text = text.Replace(" ." + Environment.NewLine, "." + Environment.NewLine);
}
if (language == "en" && text.ContainsNumber())
{
// 1 st => 1st
text = new Regex(@"(1) (st)\b").Replace(text, "$1$2");
// 2 nd => 2nd
text = new Regex(@"(2) (nd)\b").Replace(text, "$1$2");
// 3 rd => 2rd
text = new Regex(@"(3) (rd)\b").Replace(text, "$1$2");
// 4 th => 4th
text = new Regex(@"([0456789]) (th)\b").Replace(text, "$1$2");
}
if (language != "fr") // special rules for French
{
if (text.Contains(" !"))

View File

@ -594,7 +594,14 @@ namespace Test.Logic
string s = Utilities.RemoveUnneededSpaces("The time is 8. 40.", "en");
Assert.AreEqual("The time is 8.40.", s);
}
[TestMethod]
public void RemoveUnneededSpacesBetweenNumbersDates()
{
string s = Utilities.RemoveUnneededSpaces("The 4 th and 1 st 3 rd and 2 nd.", "en");
Assert.AreEqual("The 4th and 1st 3rd and 2nd.", s);
}
[TestMethod]
public void CountTagInTextStringOneLetterString()
{