mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-10-27 06:22:38 +01:00
Make "Fix music symbols" not react to hashtags
This commit is contained in:
parent
9ab1e9e3f6
commit
08b29162a4
@ -27,7 +27,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
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])));
|
||||
var isInsideFontTag = idx >= 13 && (newText[idx - 1] == '"' && newText.Length > idx + 2 && Uri.IsHexDigit(newText[idx + 1]) && Uri.IsHexDigit(newText[idx + 2]));
|
||||
if (!isInsideFontTag)
|
||||
{
|
||||
newText = newText.Remove(idx, 1);
|
||||
@ -36,11 +36,45 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
|
||||
|
||||
idx = newText.IndexOf('#', idx + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newText = newText.Replace(ms, Configuration.Settings.Tools.MusicSymbol);
|
||||
newText = newText.Replace(ms.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
|
||||
var fix = true;
|
||||
if (ms == "#" && newText.Contains("#") && !newText.Contains("# "))
|
||||
{
|
||||
int count = Utilities.CountTagInText(newText, '#');
|
||||
if (count == 1 )
|
||||
{
|
||||
var idx = newText.IndexOf('#');
|
||||
if (idx < newText.Length - 2)
|
||||
{
|
||||
if (char.IsLetterOrDigit(newText[idx + 1]))
|
||||
{
|
||||
fix = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!newText.EndsWith('#'))
|
||||
{
|
||||
var idx = newText.IndexOf('#');
|
||||
int hashTagCount = 0;
|
||||
while (idx >= 0)
|
||||
{
|
||||
if (char.IsLetterOrDigit(newText[idx + 1]))
|
||||
{
|
||||
hashTagCount++;
|
||||
}
|
||||
idx = newText.IndexOf('#', idx + 1);
|
||||
}
|
||||
fix = hashTagCount == 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (fix)
|
||||
{
|
||||
newText = newText.Replace(ms, Configuration.Settings.Tools.MusicSymbol);
|
||||
newText = newText.Replace(ms.ToUpper(), Configuration.Settings.Tools.MusicSymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
var noTagsText = HtmlUtil.RemoveHtmlTags(newText);
|
||||
|
@ -1894,6 +1894,32 @@ namespace Test
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FixMusicNotationNoHashtags()
|
||||
{
|
||||
using (var target = GetFixCommonErrorsLib())
|
||||
{
|
||||
const string s = "Lär mig #människor";
|
||||
InitializeFixCommonErrorsLine(target, s);
|
||||
Configuration.Settings.Tools.MusicSymbol = "♫";
|
||||
new FixMusicNotation().Fix(_subtitle, new EmptyFixCallback());
|
||||
Assert.AreEqual(s, _subtitle.Paragraphs[0].Text);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FixMusicNotationNoHashtagsMultiple()
|
||||
{
|
||||
using (var target = GetFixCommonErrorsLib())
|
||||
{
|
||||
const string s = "Lär mig #människor, #metoo, #timesup";
|
||||
InitializeFixCommonErrorsLine(target, s);
|
||||
Configuration.Settings.Tools.MusicSymbol = "♫";
|
||||
new FixMusicNotation().Fix(_subtitle, new EmptyFixCallback());
|
||||
Assert.AreEqual(s, _subtitle.Paragraphs[0].Text);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Fix Music Notation
|
||||
|
||||
#region FixFrenchLApostrophe
|
||||
|
Loading…
Reference in New Issue
Block a user