-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
lib/src/emojis/emojis.dart
Outdated
@@ -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) { |
There was a problem hiding this comment.
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;
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed that 👍
deb69b8
to
28646be
Compare
Fixed the formatting issue 👍 |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
This makes it easier to parse user input that may contain non-existing shortcodes