Fix "RemoveLineBreaks"

This commit is contained in:
Nikolaj Olsson 2020-06-10 05:57:14 +02:00
parent 4a89871c61
commit 0ce4101328
2 changed files with 32 additions and 16 deletions

View File

@ -651,21 +651,37 @@ namespace Nikse.SubtitleEdit.Core
public static string RemoveLineBreaks(string input)
{
var s = HtmlUtil.FixUpperTags(input);
s = s.Replace("</i> " + Environment.NewLine + "<i>", Environment.NewLine);
s = s.Replace("</i>" + Environment.NewLine + " <i>", Environment.NewLine);
s = s.Replace("</i>" + Environment.NewLine + "<i>", Environment.NewLine);
s = s.Replace(Environment.NewLine + " </i>", "</i>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + " </b>", "</b>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + " </u>", "</u>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + " </font>", "</font>" + Environment.NewLine);
s = s.Replace(" " + Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
s = s.Replace(" " + Environment.NewLine + "</b>", "</b>" + Environment.NewLine);
s = s.Replace(" " + Environment.NewLine + "</u>", "</u>" + Environment.NewLine);
s = s.Replace(" " + Environment.NewLine + "</font>", "</font>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + "</i>", "</i>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + "</b>", "</b>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + "</u>", "</u>" + Environment.NewLine);
s = s.Replace(Environment.NewLine + "</font>", "</font>" + Environment.NewLine);
s = s.Replace("</i> " + Environment.NewLine + "<i>", " ");
s = s.Replace("</i>" + Environment.NewLine + " <i>", " ");
s = s.Replace("</i>" + Environment.NewLine + "<i>", " ");
s = s.Replace(" " + Environment.NewLine + " ", " ");
s = s.Replace(Environment.NewLine + " ", " ");
s = s.Replace(" " + Environment.NewLine + " ", " ");
while (s.Contains(" " + Environment.NewLine))
{
s = s.Replace(" " + Environment.NewLine, Environment.NewLine);
}
while (s.Contains(Environment.NewLine + " "))
{
s = s.Replace(Environment.NewLine + " ", Environment.NewLine);
}
s = s.Replace(Environment.NewLine, " ");
s = s.Replace(" </i>", "</i> ");
s = s.Replace(" </b>", "</b> ");
s = s.Replace(" </u>", "</u> ");
s = s.Replace(" </font>", "</font> ");
return s.Trim();
}

View File

@ -228,7 +228,7 @@ namespace Test.Logic
var old = Configuration.Settings.General.MaxNumberOfLines;
Configuration.Settings.General.MaxNumberOfLines = 3;
Configuration.Settings.Tools.AutoBreakUsePixelWidth = false;
const string s1 = "Follow him. Day and night wherever he goes and goes and goes and goes and goes <b>again<b>!";
const string s1 = "Follow him. Day and night wherever he goes and goes and goes and goes and goes <b>again<b>!";
string s2 = Utilities.AutoBreakLine(s1);
Configuration.Settings.General.MaxNumberOfLines = old;
Assert.AreEqual("Follow him. Day and night wherever he goes" + Environment.NewLine + "and goes and goes and goes and goes <b>again<b>!", s2);
@ -680,35 +680,35 @@ namespace Test.Logic
public void RemoveLineBreaks1()
{
string result = Utilities.RemoveLineBreaks("Hey" + Environment.NewLine + "you!");
Assert.AreEqual(result, "Hey you!");
Assert.AreEqual("Hey you!", result);
}
[TestMethod]
public void RemoveLineBreaks2()
{
string result = Utilities.RemoveLineBreaks("<i>Foobar " + Environment.NewLine + "</i> foobar.");
Assert.AreEqual(result, "<i>Foobar</i> foobar.");
Assert.AreEqual("<i>Foobar</i> foobar.", result);
}
[TestMethod]
public void RemoveLineBreaks3()
{
string result = Utilities.RemoveLineBreaks("<i>Foobar " + Environment.NewLine + "</i>foobar.");
Assert.AreEqual(result, "<i>Foobar</i> foobar.");
Assert.AreEqual("<i>Foobar</i> foobar.", result);
}
[TestMethod]
public void RemoveLineBreaks4()
{
string result = Utilities.RemoveLineBreaks("<i>Hey</i>" + Environment.NewLine + "<i>you!</i>");
Assert.AreEqual(result, "<i>Hey you!</i>");
Assert.AreEqual("<i>Hey you!</i>", result);
}
[TestMethod]
public void RemoveLineBreaks5()
{
string result = Utilities.RemoveLineBreaks("<i>Foobar" + Environment.NewLine + "</i>");
Assert.AreEqual(result, "<i>Foobar</i>");
Assert.AreEqual( "<i>Foobar</i>", result);
}
[TestMethod]