Minor fix regarding reverse RTL start/end - thx OmrSi :)

Fix #2546
This commit is contained in:
Nikolaj Olsson 2017-09-04 22:08:46 +02:00
parent 2e8bb4b613
commit a98952a307
2 changed files with 25 additions and 0 deletions

View File

@ -1206,6 +1206,13 @@ namespace Nikse.SubtitleEdit.Core
s2 = s2.Remove(0, 3);
}
bool startsWithBold = false;
if (s2.StartsWith("<b>", StringComparison.Ordinal))
{
startsWithBold = true;
s2 = s2.Remove(0, 3);
}
var startFontTag = string.Empty;
if (s2.StartsWith("<font ", StringComparison.Ordinal) && s2.IndexOf('>') > 0)
{
@ -1222,6 +1229,13 @@ namespace Nikse.SubtitleEdit.Core
s2 = s2.Remove(s2.Length - endFontTag.Length);
}
bool endsWithBold = false;
if (s2.EndsWith("</b>", StringComparison.Ordinal))
{
endsWithBold = true;
s2 = s2.Remove(s2.Length - 4, 4);
}
bool endsWithItalic = false;
if (s2.EndsWith("</i>", StringComparison.Ordinal))
{
@ -1247,11 +1261,15 @@ namespace Nikse.SubtitleEdit.Core
newLines.Append(assTag);
if (startsWithItalic)
newLines.Append("<i>");
if (startsWithBold)
newLines.Append("<b>");
newLines.Append(startFontTag);
newLines.Append(ReverseParenthesis(post.ToString()));
newLines.Append(s2.Substring(pre.Length, s2.Length - (pre.Length + post.Length)));
newLines.Append(ReverseParenthesis(ReverseString(pre.ToString())));
newLines.Append(endFontTag);
if (endsWithBold)
newLines.Append("</b>");
if (endsWithItalic)
newLines.Append("</i>");
newLines.AppendLine();

View File

@ -541,5 +541,12 @@ namespace Test.Logic
"<i>.I have a big head-</i>" + Environment.NewLine + "<font color='red'>?So do I~</font>" + Environment.NewLine + "!I do too+");
}
[TestMethod]
public void ReverseStartAndEndingForRightToLeft8BoldTag()
{
Assert.AreEqual(Utilities.ReverseStartAndEndingForRightToLeft("<b>-I have a big head.</b>" + Environment.NewLine + "<font color='red'>~So do I?</font>" + Environment.NewLine + "+I do too!"),
"<b>.I have a big head-</b>" + Environment.NewLine + "<font color='red'>?So do I~</font>" + Environment.NewLine + "!I do too+");
}
}
}