/** * Splits a given text string into multiple strings no longer than maxLength bytes keeping in account emojis (even composite emojis such as flags) * * @param text input text * @param maxLength maximum length of one result string in bytes * @return List of text strings
*/ publicstatic ArrayList<String> splitEmojiText(String text, int maxLength) {
ArrayList<String> splitText = new ArrayList<>(); if (text.getBytes(StandardCharsets.UTF_8).length > maxLength) {
String toAdd;
StringBuilder newString = new StringBuilder();
for (int i = 0; i < text.length(); i++) { final EmojiParser.ParseResult result = EmojiParser.parseAt(text, i); if (result != null && result.length > 0) { // emoji found at this position
toAdd = text.substring(i, i + result.length);
i += result.length - 1;
} else {
toAdd = text.substring(i, i + 1);
}
if (newString.toString().getBytes(StandardCharsets.UTF_8).length +
toAdd.getBytes(StandardCharsets.UTF_8).length
> maxLength) {
splitText.add(newString.toString());
newString = new StringBuilder();
}
newString.append(toAdd);
} if (!newString.toString().isEmpty()) {
splitText.add(newString.toString());
}
} else {
splitText.add(text);
} return splitText;
}
/** * Check if the query matches the text. A query matches the text if * <ul> * <li>the text contains the query, or</li> * <li>the normalized text without the diacritics contains the query.</li> * </ul> * <p> * If any of the arguments is null, {@code false} is returned. * * @return {@code true} if there is a match, {@code false} otherwise
*/ publicstaticboolean matchesQueryDiacriticInsensitive(@Nullable String text, @Nullable String query) { if (text == null || query == null) { returnfalse;
}
text = text.toUpperCase();
query = query.toUpperCase();
if (text.contains(query)) { returntrue;
}
// Only normalize the query without removing the diacritics
String queryNorm = Normalizer.isNormalized(query, Normalizer.Form.NFD)
? query
: Normalizer.normalize(query, Normalizer.Form.NFD);
// Normalize conversation and remove diacritics
String conversationNormDiacritics = LocaleUtil.normalize(text);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.