diff --git a/src/Test/Core/StringExtensionsTest.cs b/src/Test/Core/StringExtensionsTest.cs
index e16663cc7..0bf4cec9e 100644
--- a/src/Test/Core/StringExtensionsTest.cs
+++ b/src/Test/Core/StringExtensionsTest.cs
@@ -403,6 +403,22 @@ namespace Test.Core
Assert.AreEqual("How Are You?", res);
}
+ [TestMethod]
+ public void ToLowercaseButKeepTags1()
+ {
+ var input = "HOW ARE YOU?";
+ var res = input.ToLowercaseButKeepTags();
+ Assert.AreEqual("how are you?", res);
+ }
+
+ [TestMethod]
+ public void ToLowercaseButKeepTags2()
+ {
+ var input = "{\\c&H0000FF&}Red";
+ var res = input.ToLowercaseButKeepTags();
+ Assert.AreEqual("{\\c&H0000FF&}red", res);
+ }
+
[TestMethod]
public void HasSentenceEndingCultureNeutralTest()
{
diff --git a/src/libse/Common/FixCasing.cs b/src/libse/Common/FixCasing.cs
index fa5da1a04..cd6fa49e8 100644
--- a/src/libse/Common/FixCasing.cs
+++ b/src/libse/Common/FixCasing.cs
@@ -250,7 +250,7 @@ namespace Nikse.SubtitleEdit.Core.Common
var text = original;
if (FixNormal)
{
- if (FixNormalOnlyAllUppercase && text != text.ToUpper(subtitleCulture))
+ if (FixNormalOnlyAllUppercase && HtmlUtil.RemoveHtmlTags(text, true) != HtmlUtil.RemoveHtmlTags(text, true).ToUpper(subtitleCulture))
{
return text;
}
@@ -258,7 +258,7 @@ namespace Nikse.SubtitleEdit.Core.Common
if (text.Length > 1)
{
// first all to lower
- text = text.ToLower(subtitleCulture).Trim();
+ text = text.ToLowercaseButKeepTags().Trim();
text = text.FixExtraSpaces();
var st = new StrippableText(text);
st.FixCasing(nameList, false, true, true, lastLine, millisecondsFromLast); // fix all casing but names (that's a separate option)
diff --git a/src/libse/Common/StringExtensions.cs b/src/libse/Common/StringExtensions.cs
index 92aacd5b9..d7c8c2cec 100644
--- a/src/libse/Common/StringExtensions.cs
+++ b/src/libse/Common/StringExtensions.cs
@@ -500,6 +500,19 @@ namespace Nikse.SubtitleEdit.Core.Common
return RestoreSavedTags(properCaseText, tags);
}
+ public static string ToLowercaseButKeepTags(this string input)
+ {
+ if (string.IsNullOrWhiteSpace(input))
+ {
+ return input;
+ }
+
+ var sb = new StringBuilder();
+ var tags = RemoveAndSaveTags(input, sb, new SubRip());
+ var lowercaseText = sb.ToString().ToLowerInvariant();
+ return RestoreSavedTags(lowercaseText, tags);
+ }
+
public static string ToggleCasing(this string input, SubtitleFormat format, string overrideFromStringInit = null)
{
if (string.IsNullOrWhiteSpace(input))