Fix issue #448 - Issue with regex for whole word

This commit is contained in:
Thomas 2022-11-13 10:49:04 +01:00
parent 6063246b96
commit 435c34604b
1 changed files with 4 additions and 4 deletions

View File

@ -92,19 +92,19 @@ public class TimelineHelper {
//If there are filters: //If there are filters:
if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) { if (BaseMainActivity.mainFilters != null && BaseMainActivity.mainFilters.size() > 0 && statuses != null && statuses.size() > 0) {
for (Filter filter : BaseMainActivity.mainFilters) { for (Filter filter : BaseMainActivity.mainFilters) {
if (filter.irreversible) { //Dealt by the server
continue;
}
for (String filterContext : filter.context) { for (String filterContext : filter.context) {
if (filterTimeLineType.getValue().equalsIgnoreCase(filterContext)) { if (filterTimeLineType.getValue().equalsIgnoreCase(filterContext)) {
if (filter.whole_word) { if (filter.whole_word) {
Pattern p = Pattern.compile("(^" + Pattern.quote(filter.phrase) + "\\b|\\b" + Pattern.quote(filter.phrase) + "$)", Pattern.CASE_INSENSITIVE);
Pattern p = Pattern.compile("\\b(" + Pattern.quote(filter.phrase) + ")\\b", Pattern.CASE_INSENSITIVE);
for (Status status : statuses) { for (Status status : statuses) {
String content; String content;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content, Html.FROM_HTML_MODE_LEGACY).toString(); content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content, Html.FROM_HTML_MODE_LEGACY).toString();
else else
content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content).toString(); content = Html.fromHtml(status.reblog != null ? status.reblog.content : status.content).toString();
Matcher m = p.matcher(content); Matcher m = p.matcher(content);
if (m.find()) { if (m.find()) {
statusesToRemove.add(status); statusesToRemove.add(status);