diff --git a/src/libse/Common/Utilities.cs b/src/libse/Common/Utilities.cs index 2699966382..ac1311a91c 100644 --- a/src/libse/Common/Utilities.cs +++ b/src/libse/Common/Utilities.cs @@ -345,14 +345,7 @@ public static string AutoBreakLineMoreThanTwoLines(string text, int maximumLengt { string tag = s.Substring(six, endIndex - six + 1); s = s.Remove(six, tag.Length); - if (htmlTags.ContainsKey(six)) - { - htmlTags[six] = htmlTags[six] + tag; - } - else - { - htmlTags.Add(six, tag); - } + AddOrAppendHtmlTag(htmlTags, six, tag); } else { @@ -434,6 +427,18 @@ public static string AutoBreakLineMoreThanTwoLines(string text, int maximumLengt return text; } + private static void AddOrAppendHtmlTag(Dictionary htmlTags, int index, string tag) + { + if (htmlTags.TryGetValue(index, out var existing)) + { + htmlTags[index] = existing + tag; + } + else + { + htmlTags.Add(index, tag); + } + } + private static string ReInsertHtmlTagsAndCleanUp(string input, Dictionary htmlTags) { var s = ReInsertHtmlTags(input, htmlTags); @@ -604,14 +609,7 @@ public static string AutoBreakLinePrivate(string input, int maximumLength, int m if (endIndexAssTag > 0) { tagString = tagString.Substring(0, endIndexAssTag); - if (htmlTags.ContainsKey(six)) - { - htmlTags[six] = htmlTags[six] + tagString; - } - else - { - htmlTags.Add(six, tagString); - } + AddOrAppendHtmlTag(htmlTags, six, tagString); s = s.Remove(six, endIndexAssTag); continue; @@ -628,14 +626,7 @@ public static string AutoBreakLinePrivate(string input, int maximumLength, int m { var tag = s.Substring(six, endIndex - six + 1); s = s.Remove(six, tag.Length); - if (htmlTags.ContainsKey(six)) - { - htmlTags[six] += tag; - } - else - { - htmlTags.Add(six, tag); - } + AddOrAppendHtmlTag(htmlTags, six, tag); } else {