mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 19:22:53 +01:00
parent
cd4912827c
commit
3fe480d1d0
@ -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;
|
||||
|
@ -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(" !"))
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user