Liberal word boundary

This commit is contained in:
M66B 2023-08-20 09:56:17 +02:00
parent c0cec6737c
commit 7a648035e7
1 changed files with 6 additions and 2 deletions

View File

@ -897,14 +897,18 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
if (word.size() == 0)
return true;
// \b is limited to [0-9A-Za-z_]
String b = "(^|\\s+)";
String a = "($|\\s+)";
StringBuilder sb = new StringBuilder();
sb.append(partial ? ".*(" : ".*?\\b(");
sb.append(partial ? ".*(" : ".*?" + b + "(");
for (int i = 0; i < word.size(); i++) {
if (i > 0)
sb.append("\\s+");
sb.append(Pattern.quote(word.get(i)));
}
sb.append(partial ? ").*" : ")\\b.*?");
sb.append(partial ? ").*" : ")" + a + ".*?");
Pattern pat = Pattern.compile(sb.toString(), Pattern.DOTALL);
return pat.matcher(text).matches();