From 0745d49f44e872d289bee9e2b9e861735ffb1ee7 Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Sun, 31 Dec 2023 06:24:23 +0200 Subject: [PATCH] Use native method for enumerating runes --- .../Discord/Data/Common/ImageCdn.cs | 3 +-- .../Utils/Extensions/StringExtensions.cs | 11 ----------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/DiscordChatExporter.Core/Discord/Data/Common/ImageCdn.cs b/DiscordChatExporter.Core/Discord/Data/Common/ImageCdn.cs index 4c44341..90a282f 100644 --- a/DiscordChatExporter.Core/Discord/Data/Common/ImageCdn.cs +++ b/DiscordChatExporter.Core/Discord/Data/Common/ImageCdn.cs @@ -1,7 +1,6 @@ using System; using System.Globalization; using System.Linq; -using DiscordChatExporter.Core.Utils.Extensions; namespace DiscordChatExporter.Core.Discord.Data.Common; @@ -11,7 +10,7 @@ public static class ImageCdn // Standard emoji are rendered through Twemoji public static string GetStandardEmojiUrl(string emojiName) { - var runes = emojiName.GetRunes().ToArray(); + var runes = emojiName.EnumerateRunes().ToArray(); // Variant selector rune is skipped in Twemoji IDs, // except when the emoji also contains a zero-width joiner. diff --git a/DiscordChatExporter.Core/Utils/Extensions/StringExtensions.cs b/DiscordChatExporter.Core/Utils/Extensions/StringExtensions.cs index e1443bc..de035fb 100644 --- a/DiscordChatExporter.Core/Utils/Extensions/StringExtensions.cs +++ b/DiscordChatExporter.Core/Utils/Extensions/StringExtensions.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Text; namespace DiscordChatExporter.Core.Utils.Extensions; @@ -27,16 +26,6 @@ public static class StringExtensions return builder.ToString(); } - public static IEnumerable GetRunes(this string str) - { - var lastIndex = 0; - while (lastIndex < str.Length && Rune.TryGetRuneAt(str, lastIndex, out var rune)) - { - yield return rune; - lastIndex += rune.Utf16SequenceLength; - } - } - public static T? ParseEnumOrNull(this string str, bool ignoreCase = true) where T : struct, Enum => Enum.TryParse(str, ignoreCase, out var result) ? result : null;