Beispiel #1
0
        /// <summary>
        ///     Returns a replace pattern for the specified emoji
        /// </summary>
        /// <param name="emojiName">The emoji name</param>
        /// <returns>A regex replace pattern</returns>
        private string GitHubify_Emoji(string emojiName)
        {
            // TODO: Use inline images instead of unicode characters, which are just rendered in B/W
            if (emojis == null)
            {
                const string url  = "https://api.github.com/emojis";
                var          list = this.DownloadJsonInternal <Dictionary <string, string> >(url);
                emojis = list.Count <= 0
                    ? new List <Emoji>(0)
                    : list.Select(kvp => new Emoji {
                    Name = kvp.Key, Url = kvp.Value
                }).ToList();
            }

            if (emojis.Count <= 0)
            {
                return(string.Empty);
            }

            Emoji emoji = emojis.SingleOrDefault(e => e.Name == emojiName);

            if (emoji == null)
            {
                return("$_");
            }

            string unicodeString = emoji.GetAsUnicodeString();

            return(string.IsNullOrWhiteSpace(unicodeString) ? string.Empty : unicodeString);
        }