splitTextByEmojiAndAtUsers static method
Implementation
static Map<String, List<String>> splitTextByEmojiAndAtUsers(String text, List<String> userList) {
if (text == null || text.isEmpty) {
return {};
}
List<String> result = [];
List<String> atUsers = [];
if (userList != null && userList.isNotEmpty) {
for (String user in userList) {
String atUser = "@$user";
atUsers.add(atUser);
}
}
List<String> splitResultByAtUsers = splitByKeyList(atUsers, text);
int textIndex = 0;
List<String> needTranslationTextIndexList = [];
for (int i = 0; i < splitResultByAtUsers.length; i++) {
String splitString = splitResultByAtUsers[i];
if (atUsers.isNotEmpty && atUsers.contains(splitString)) {
result.add(splitString);
textIndex++;
} else {
List<String> emojiKeyList = FaceManager.findEmojiKeyListFromText(splitString);
if (emojiKeyList != null && emojiKeyList.isNotEmpty) {
List<String> splitByEmojiResultList = splitByKeyList(emojiKeyList, splitString);
for (int j = 0; j < splitByEmojiResultList.length; j++) {
String splitStringByEmoji = splitByEmojiResultList[j];
result.add(splitStringByEmoji);
String emojiKey = "";
if (emojiKeyList.isNotEmpty) {
emojiKey = emojiKeyList[0];
}
if (emojiKey.isNotEmpty && splitStringByEmoji == emojiKey) {
emojiKeyList.removeAt(0);
} else if (splitStringByEmoji.trim().isNotEmpty) {
needTranslationTextIndexList.add(textIndex.toString());
}
textIndex++;
}
} else {
if (splitString.trim().isNotEmpty) {
needTranslationTextIndexList.add(textIndex.toString());
}
result.add(splitString);
textIndex++;
}
}
}
List<String> needTranslationTextList = [];
for (int i = 0; i < needTranslationTextIndexList.length; i++) {
int needTranslationIndex = int.parse(needTranslationTextIndexList[i]);
needTranslationTextList.add(result[needTranslationIndex]);
}
Map<String, List<String>> resultMap = {
splitText: result,
splitTextForTranslation: needTranslationTextList,
splitTextIndexForTranslation: needTranslationTextIndexList,
};
return resultMap;
}