From ef6f07492399fb29b6e3ad55b9c2609b5a84d885 Mon Sep 17 00:00:00 2001 From: niksedk Date: Sun, 21 Apr 2019 07:40:33 +0200 Subject: [PATCH] Fix "reverse rtl" issue with music symbols - thx OmrSi :) See https://github.com/SubtitleEdit/subtitleedit/commit/5a5300583a52767152b0cd80dbad1bbba9462043#commitcomment-33215599 --- libse/Utilities.cs | 24 ++++++++++++++++++++++++ src/Test/Logic/UtilitiesTest.cs | 14 ++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/libse/Utilities.cs b/libse/Utilities.cs index 859edb6dd..d309b25c4 100644 --- a/libse/Utilities.cs +++ b/libse/Utilities.cs @@ -1450,6 +1450,18 @@ namespace Nikse.SubtitleEdit.Core string postTags = string.Empty; for (int k = 0; k < 10; k++) { + if (s2.StartsWith("♪ ", StringComparison.Ordinal) || + s2.StartsWith("♫ ", StringComparison.Ordinal)) + { + preTags.Append(s2.Substring(0, 2)); + s2 = s2.Remove(0, 2); + } + if (s2.StartsWith("♪", StringComparison.Ordinal) || + s2.StartsWith("♫", StringComparison.Ordinal)) + { + preTags.Append(s2.Substring(0, 1)); + s2 = s2.Remove(0, 1); + } if (s2.StartsWith("", StringComparison.Ordinal) || s2.StartsWith("", StringComparison.Ordinal) || s2.StartsWith("", StringComparison.Ordinal)) @@ -1465,6 +1477,18 @@ namespace Nikse.SubtitleEdit.Core s2 = s2.Remove(0, idx); } + if (s2.EndsWith(" ♪", StringComparison.Ordinal) || + s2.EndsWith(" ♫", StringComparison.Ordinal)) + { + postTags = s2.Substring(s2.Length - 2) + postTags; + s2 = s2.Remove(s2.Length - 2); + } + if (s2.EndsWith("♪", StringComparison.Ordinal) || + s2.EndsWith("♫", StringComparison.Ordinal)) + { + postTags = s2.Substring(s2.Length - 1) + postTags; + s2 = s2.Remove(s2.Length - 1); + } if (s2.EndsWith("", StringComparison.Ordinal) || s2.EndsWith("", StringComparison.Ordinal) || s2.EndsWith("", StringComparison.Ordinal)) diff --git a/src/Test/Logic/UtilitiesTest.cs b/src/Test/Logic/UtilitiesTest.cs index ea2a40af7..b3cbbe36c 100644 --- a/src/Test/Logic/UtilitiesTest.cs +++ b/src/Test/Logic/UtilitiesTest.cs @@ -737,5 +737,19 @@ namespace Test.Logic var result = Utilities.ReverseStartAndEndingForRightToLeft("\"Hey." + Environment.NewLine + "Hey.\""); Assert.AreEqual(".Hey\"" + Environment.NewLine + "\".Hey", result); } + + [TestMethod] + public void ReverseStartAndEndingForRightToLeftMusicSymbols() + { + var result = Utilities.ReverseStartAndEndingForRightToLeft("♪ Hey... ♪"); + Assert.AreEqual("♪ ...Hey ♪", result); + } + + [TestMethod] + public void ReverseStartAndEndingForRightToLeftMusicSymbols2() + { + var result = Utilities.ReverseStartAndEndingForRightToLeft("♫Hey...♫"); + Assert.AreEqual("♫...Hey♫", result); + } } }