-
Notifications
You must be signed in to change notification settings - Fork 32
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
Can it detect a string is all emoji or not? #3
Comments
You can use parser.unemojify('I ❤️ ☕'); // returns: 'I :heart: :coffee:' Now, if all words are emojis then each should start with a |
@petehouston What about text in the middle? such as |
@petehouston Wanna it contains continuesly pure emoji then mark it as true, otherwise treat as normal. |
Maybe there is a better way to do this but following @petehouston comment I did something like this import 'package:flutter_emoji/flutter_emoji.dart';
/*code*/
bool isAllEmoji(String text) {
for (String s in EmojiParser().unemojify(text).split(" ")) if (!s.startsWith(":") || !s.endsWith(":")) return false;
return true;
} |
I think we have check one more condition for this
|
This is the correct solution. bool hasOnlyEmojis(String input) {
// find all emojis
final emojis = EmojiParser().parseEmojis(input);
// return if none found
if (emojis.isEmpty) return false;
// remove all emojis from the input
for (final emoji in emojis) {
input = input.replaceAll(emoji, "");
}
// remove all whitespace (optional)
input = input.replaceAll(" ", "");
// return true if nothing else left
return input.isEmpty;
} |
All of this works, unless you use the emojis that have color UPDATEThis works: final emojisRegExp =
RegExp(r"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])");
bool isOnlyEmojis(String text) {
// find all emojis
final emojis = emojisRegExp.allMatches(text);
// return if none found
if (emojis.isEmpty) return false;
// remove all emojis from the this
for (final emoji in emojis) {
text = text.replaceAll(emoji.input.substring(emoji.start, emoji.end), "");
}
// remove all whitespace (optional)
text = text.replaceAll(" ", "");
// return true if nothing else left
return text.isEmpty;
}
/// True if the string is only emojis and the number of emojis is less than [maxEmojis]
bool isLessEmojisThan(String text, int maxEmojis) {
final allEmojis = emojisRegExp.allMatches(text);
final numEmojis = allEmojis.length;
if (numEmojis < maxEmojis && isOnlyEmojis(text)) {
return true;
}
return false;
} |
your code helps me. TNX |
still does not work for many emojis with skin tone set or for all emojis. Need a way to expand the list of emojis to match and support skin tone match. |
Hi Sir, thanks for this useful repo.
I wanna detect a string is all emoji or not, take an example:
😄😄 -> yes
😄 ff -> not
So how to achieve that using this repo? thanks in advance!
The text was updated successfully, but these errors were encountered: