Merge pull request #1424 from ivandrofly/patch-12

[Bugfix] - Fix bug when FCE Paragraph with #
This commit is contained in:
Nikolaj Olsson 2015-12-02 06:31:30 +01:00
commit 62682395e6
2 changed files with 46 additions and 3 deletions

View File

@ -17,11 +17,30 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
var oldText = p.Text;
var newText = oldText;
bool containsFontTag = oldText.Contains("<font ", StringComparison.OrdinalIgnoreCase);
foreach (string musicSymbol in musicSymbols)
{
newText = newText.Replace(musicSymbol, Configuration.Settings.Tools.MusicSymbol);
newText = newText.Replace(musicSymbol.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
if (containsFontTag && musicSymbol == "#")
{
var idx = newText.IndexOf('#');
while (idx >= 0)
{
// <font color="#808080">NATIVE HAWAIIAN CHANTING</font>
var isInsideFontTag = (idx < 13) ? false : (newText[idx - 1] == '"' && (newText.Length > idx + 2 && Uri.IsHexDigit(newText[idx + 1]) && Uri.IsHexDigit(newText[idx + 2])));
if (!isInsideFontTag)
{
newText = newText.Remove(idx, 1);
newText = newText.Insert(idx, musicSymbol);
}
idx = newText.IndexOf('#', idx + 1);
}
}
else
{
newText = newText.Replace(musicSymbol, Configuration.Settings.Tools.MusicSymbol);
newText = newText.Replace(musicSymbol.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
}
}
var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
if (newText != oldText && noTagsText != HtmlUtil.RemoveHtmlTags(oldText))

View File

@ -1614,5 +1614,29 @@ namespace Test
}
}
#endregion
#region Fix Music Notation
[TestMethod]
public void FixMusicNotation1()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "John: <font color=\"#ffff80\">Hello world.</font>");
new FixMusicNotation().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("John: <font color=\"#ffff80\">Hello world.</font>", _subtitle.Paragraphs[0].Text);
}
}
[TestMethod]
public void FixMusicNotation2()
{
using (var target = GetFixCommonErrorsLib())
{
InitializeFixCommonErrorsLine(target, "# Hello world. #");
new FixMusicNotation().Fix(_subtitle, new EmptyFixCallback());
Assert.AreEqual("♪ Hello world. ♪", _subtitle.Paragraphs[0].Text);
}
}
#endregion
}
}