Skip to content

Commit

Permalink
Use native method for enumerating runes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Dec 31, 2023
1 parent c16e14e commit 0745d49
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 13 deletions.
3 changes: 1 addition & 2 deletions DiscordChatExporter.Core/Discord/Data/Common/ImageCdn.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using System.Linq;
using DiscordChatExporter.Core.Utils.Extensions;

namespace DiscordChatExporter.Core.Discord.Data.Common;

Expand All @@ -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.
Expand Down
11 changes: 0 additions & 11 deletions DiscordChatExporter.Core/Utils/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace DiscordChatExporter.Core.Utils.Extensions;
Expand Down Expand Up @@ -27,16 +26,6 @@ public static string ToSpaceSeparatedWords(this string str)
return builder.ToString();
}

public static IEnumerable<Rune> 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<T>(this string str, bool ignoreCase = true)
where T : struct, Enum => Enum.TryParse<T>(str, ignoreCase, out var result) ? result : null;

Expand Down

0 comments on commit 0745d49

Please sign in to comment.