From 720adee90822be3962a8731994d72d9b3b3ee6ba Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Mon, 7 Aug 2017 19:32:38 +0200 Subject: [PATCH] Minor refactor - fix #2508 - thx ivandrofly :) --- libse/SubtitleFormats/DCSubtitle.cs | 18 ++++-------- libse/SubtitleFormats/DCinemaSmpte2010.cs | 34 ++--------------------- 2 files changed, 8 insertions(+), 44 deletions(-) diff --git a/libse/SubtitleFormats/DCSubtitle.cs b/libse/SubtitleFormats/DCSubtitle.cs index 707bf1933..ba9f731be 100644 --- a/libse/SubtitleFormats/DCSubtitle.cs +++ b/libse/SubtitleFormats/DCSubtitle.cs @@ -670,30 +670,22 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Renumber(); } - private static string GetColorStringFromDCinema(string s) + internal static string GetColorStringFromDCinema(string s) { if (string.IsNullOrWhiteSpace(s)) { return s; } - if (s[0] == '#') - { - s = s.Substring(1); - } - var chars = new char[s.Length]; + + var hex = s.TrimStart('#'); for (int i = s.Length - 1; i >= 0; i--) { - char ch = s[i]; - if (CharUtils.IsHexadecimal(ch)) - { - chars[i] = ch; - } - else + if (!CharUtils.IsHexadecimal(s[i])) { return s; } } - return "#" + new string(chars); + return "#" + hex; } private static TimeCode GetTimeCode(string s) diff --git a/libse/SubtitleFormats/DCinemaSmpte2010.cs b/libse/SubtitleFormats/DCinemaSmpte2010.cs index 74bfcbce6..1dd4cb9e8 100644 --- a/libse/SubtitleFormats/DCinemaSmpte2010.cs +++ b/libse/SubtitleFormats/DCinemaSmpte2010.cs @@ -654,16 +654,16 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase)) { if (innerInnerNode.Attributes["Color"] != null) - pText.Append("" + innerInnerNode.InnerText + ""); + pText.Append("" + innerInnerNode.InnerText + ""); else pText.Append("" + innerInnerNode.InnerText + ""); } else if (innerInnerNode.Name == "Font" && innerInnerNode.Attributes["Color"] != null) { if (innerInnerNode.Attributes["Italic"] != null && innerInnerNode.Attributes["Italic"].InnerText.Equals("yes", StringComparison.OrdinalIgnoreCase)) - pText.Append("" + innerInnerNode.InnerText + ""); + pText.Append("" + innerInnerNode.InnerText + ""); else - pText.Append("" + innerInnerNode.InnerText + ""); + pText.Append("" + innerInnerNode.InnerText + ""); } else { @@ -706,34 +706,6 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats subtitle.Renumber(); } - private static string GetColorStringFromDCinema(string p) - { - string s = p.ToLower().Trim(); - if (s.Replace("#", string.Empty). - Replace("0", string.Empty). - Replace("1", string.Empty). - Replace("2", string.Empty). - Replace("3", string.Empty). - Replace("4", string.Empty). - Replace("5", string.Empty). - Replace("6", string.Empty). - Replace("7", string.Empty). - Replace("8", string.Empty). - Replace("9", string.Empty). - Replace("a", string.Empty). - Replace("b", string.Empty). - Replace("c", string.Empty). - Replace("d", string.Empty). - Replace("e", string.Empty). - Replace("f", string.Empty).Length == 0) - { - if (s.StartsWith('#')) - return s; - return "#" + s; - } - return p; - } - private TimeCode GetTimeCode(string s) { var parts = s.Split(new[] { ':', '.', ',' });