getDetections method
Return the list of decorations with tagged and untagged text
Implementation
List<Detection> getDetections(String copiedText) {
/// Text to change emoji into replacement text
final fullWidthRegExp = RegExp(
r'(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])');
final fullWidthRegExpMatches =
fullWidthRegExp.allMatches(copiedText).toList();
final tokenRegExp =
RegExp(r'[・ぁ-んーァ-ヶ一-龥\u1100-\u11FF\uAC00-\uD7A30-9a-zA-Z ]');
final emojiMatches = fullWidthRegExpMatches
.where((match) => (!tokenRegExp
.hasMatch(copiedText.substring(match.start, match.end))))
.toList();
/// This is to avoid the error caused by 'regExp' which counts the emoji's length 1.
emojiMatches.forEach((emojiMatch) {
final emojiLength = emojiMatch.group(0)!.length;
final replacementText = "a" * emojiLength;
copiedText = copiedText.replaceRange(
emojiMatch.start, emojiMatch.end, replacementText);
});
final tags = detectionRegExp.allMatches(copiedText).toList();
if (tags.isEmpty) {
return [];
}
final sourceDetections = _getSourceDetections(tags, copiedText);
final emojiFilteredResult = _getEmojiFilteredDetections(
copiedText: copiedText,
emojiMatches: emojiMatches,
source: sourceDetections);
return emojiFilteredResult;
}