Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional fallback getter when parsing string with shortcodes #4

Merged
merged 5 commits into from
Mar 21, 2024

Conversation

ndelanou
Copy link
Contributor

@ndelanou ndelanou commented Mar 20, 2024

This makes it easier to parse user input that may contain non-existing shortcodes

@@ -60,15 +60,14 @@ class Emojis {
/// Returns the Emoji with the specified value, unicode, name, or shortcode.
/// If the specified Emoji cannot be found, the orElse parameter is called, and its
/// return value is returned. If orElse is not specified, a [StateError] is thrown.
Emoji getOne(String param, {Emoji Function()? orElse}) {
return _emojis.firstWhere(
Emoji? getOne(String param) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a method that covers this:

It's called getOneOrNull

So instead of changing thisgetOne method. You could use getOneOrNull directly then:

  String fromShortcodes({String Function(String unknownShortcode)? onUnknownShortcode}) {
    return _value.splitMapJoin(Regex.shortcode, onMatch: (m) {
      final match = m.group(0)!;
      return _emojis.getOneOrNull(match.removeColons())?.value ?? onUnknownShortcode?.call(match) ?? match;
    });
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that 👍

@ndelanou ndelanou force-pushed the feat/shortcode-parsing-fallback branch from deb69b8 to 28646be Compare March 21, 2024 15:45
@ndelanou
Copy link
Contributor Author

Fixed the formatting issue 👍

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b4b27f5) to head (37a194a).

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #4   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines          309       311    +2     
=========================================
+ Hits           309       311    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Nikoro Nikoro merged commit c4f0376 into Nikoro:main Mar 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants