コード例 #1
0
        public void Demojify()
        {
            Emoji.Demojify("Hello, 🌍").Should().Be("Hello, :earth_africa:");
            Emoji.Demojify("Hello, 👱‍♀️").Should().Be("Hello, :blond_haired_woman:");
            Emoji.Demojify("Hello, 字").Should().Be("Hello, 字");

            Action act = () => Emoji.Demojify(NullString);

            act.Should().Throw <ArgumentNullException>();
        }
コード例 #2
0
 public void Emoji_()
 {
     WriteLine(Emoji.Get(":tada:").Raw);                // 🎉
     WriteLine(Emoji.Get("🎉").Alias());                 // :tada:
     WriteLine(Emoji.Raw(":tada:"));                    // 🎉
     WriteLine(Emoji.Alias("🎉"));                       // :tada:
     WriteLine(Emoji.Emojify(":tada: initial commit")); // 🎉 initial commit
     WriteLine(Emoji.Demojify("🎉 initial commit"));     // :tada: initial commit
     WriteLine(Emoji.Find("party popper").First().Raw); // 🎉
 }
コード例 #3
0
        /// <summary>
        /// Return a filtered list, based on the given query.
        /// </summary>
        /// <param name="query">The query to filter the list.</param>
        /// <returns>A filtered list, can be empty when nothing was found.</returns>
        public List <Result> Query(Query query)
        {
            if (query?.Search is null)
            {
                return(new List <Result>(0));
            }

            var value = query.Search;

            if (string.IsNullOrEmpty(value))
            {
                return(Emoji.All.Select(GetResult).ToList());
            }

            var emojis = Emoji.Find(value);

            if (emojis.Any())
            {
                return(emojis.Select(GetResult).ToList());
            }

            var results = new List <Result>();

            if (HasAlias(value))
            {
                var result = Emoji.Emojify(value);

                results.Add(
                    new Result
                {
                    QueryTextDisplay = value,
                    IcoPath          = IconPath,
                    Title            = result,
                    SubTitle         = "Replace aliases in text with raw emojis",
                    ToolTipData      = new ToolTipData("Emojify", $"{value}\n{result}"),
                    Action           = _ => CopyToClipboard(result),
                    ContextData      = new EmojifiedString(result),
                });
            }

            if (HasEmoji(value))
            {
                var result = Emoji.Demojify(value);

                results.Add(
                    new Result
                {
                    QueryTextDisplay = value,
                    IcoPath          = IconPath,
                    Title            = result,
                    SubTitle         = "Replace raw emojis in text with aliases",
                    ToolTipData      = new ToolTipData("Demojify", $"{value}\n{result}"),
                    Action           = _ => CopyToClipboard(result),
                    ContextData      = new DemojifiedString(result),
                });
            }

            return(results);

            Result GetResult(GEmoji emoji) => new()
            {
                QueryTextDisplay = value,
                IcoPath          = IconPath,
                Title            = emoji.Raw,
                SubTitle         = string.Join(" ", emoji.Aliases.Select(x => x.PadAlias())),
                ToolTipData      = new ToolTipData("GEmoji", $"Description: {emoji.Description}\nCategory: {emoji.Category}\nTags: {string.Join(", ", emoji.Tags ?? Enumerable.Empty<string>())}\n"),
                Action           = _ => CopyToClipboard(emoji.Raw),
                ContextData      = emoji,
            };

            bool HasAlias(string value)
            {
                return(Regex.IsMatch(value, @":([\w+-]+):", RegexOptions.Compiled));
            }

            bool HasEmoji(string value)
            {
                return(Regex.IsMatch(value, Emoji.RegexPattern, RegexOptions.Compiled));
            }
        }