Comments (9)
You can use
parse.unemojify()
which is to convert the emoji string info text format, then verify the text.parser.unemojify('I ❤️ ☕'); // returns: 'I :heart: :coffee:'Now, if all words are emojis then each should start with a
:
and end with a:
; otherwise, it is not an emoji.
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;
}
from flutter-emoji.
You can use parse.unemojify()
which is to convert the emoji string info text format, then verify the text.
parser.unemojify('I ❤️ ☕'); // returns: 'I :heart: :coffee:'
Now, if all words are emojis then each should start with a :
and end with a :
; otherwise, it is not an emoji.
from flutter-emoji.
All of this works, unless you use the emojis that have color 👍🏻
UPDATE
This 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;
}
from flutter-emoji.
@petehouston What about text in the middle?
such as 😄😄hahah😄
from flutter-emoji.
@petehouston Wanna it contains continuesly pure emoji then mark it as true, otherwise treat as normal.
from flutter-emoji.
You can use
parse.unemojify()
which is to convert the emoji string info text format, then verify the text.parser.unemojify('I ❤️ ☕'); // returns: 'I :heart: :coffee:'Now, if all words are emojis then each should start with a
:
and end with a:
; otherwise, it is not an emoji.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
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;
}
List<String> parseEmoji = EmojiParser().parseEmojis(text);
if(parseEmoji.isNotEmpty) {
String text1 = text;
for(String s in parseEmoji) {
text1 = text1.replaceAll(s, "");
}
if(text1.isNotEmpty) {
return false;
}
}
return true;
}
from flutter-emoji.
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;
}
from flutter-emoji.
All of this works, unless you use the emojis that have color
👍🏻
UPDATE
This 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
from flutter-emoji.
Related Issues (20)
- how to detect a sentence is pure emoji or not? HOT 4
- Support Emoji Unicode 13.0 HOT 1
- Regex does not work because it will include some Chinese characters such as "。" (the "." in Chinese which is very common)
- JSON_EMOJI not complete HOT 1
- How to use it description is not clear that's why it is not most popular and users are not able to use them in their project
- Please provide a list of supported emojis with their code and images HOT 3
- Migrate to Sound Null Safety HOT 7
- How can you list all available emojis? HOT 1
- Example folder missing main.dart
- Emoji with Additional Characters
- Support Emoji Unicode v15.0 HOT 1
- update dependencies, http: ^1.0.0 is not supported HOT 3
- Synchronize with node-emoji source
- Allow any replacement or deletion
- Substitute dash with underscore in JSON_EMOJI string HOT 1
- Wrong REGEX_NAME value HOT 3
- Can this library display emojis the phone does not have? HOT 2
- Emoji Regex HOT 7
- App crashes when I install the package HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter-emoji.