Merge pull request #1413 from ivandrofly/patch-715

Fix Autobreak fuction
This commit is contained in:
Nikolaj Olsson 2015-11-09 18:54:57 +01:00
commit a6b40291df
2 changed files with 22 additions and 1 deletions

View File

@ -620,9 +620,19 @@ namespace Nikse.SubtitleEdit.Core
s = s.Substring(0, splitPos) + Environment.NewLine + s.Substring(splitPos);
s = ReInsertHtmlTags(s, htmlTags);
var idx = s.IndexOf(Environment.NewLine + "</");
if (idx > 2)
{
var endIdx = s.IndexOf('>', idx + 2);
if (endIdx > idx)
{
var tag = s.Substring(idx + Environment.NewLine.Length, endIdx - (idx + Environment.NewLine.Length) + 1);
s = s.Insert(idx, tag);
s = s.Remove(idx + tag.Length + Environment.NewLine.Length, tag.Length);
}
}
s = s.Replace(" " + Environment.NewLine, Environment.NewLine);
s = s.Replace(Environment.NewLine + " ", Environment.NewLine);
return s.TrimEnd();
}

View File

@ -48,6 +48,17 @@ namespace Test.Logic
Assert.AreEqual(target, s2);
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void AutoBreakLine5()
{
Configuration.Settings.General.SubtitleLineMaximumLength = 43;
const string s1 = "<i>30 years ago I'd found</i> The Book of the Dead.";
var s2 = Utilities.AutoBreakLine(s1);
var Expected = "<i>30 years ago I'd found</i>" + Environment.NewLine + "The Book of the Dead.";
Assert.AreEqual(Expected, s2);
}
[TestMethod]
[DeploymentItem("SubtitleEdit.exe")]
public void AutoBreakLine5DoNoBreakAtPeriod()