isBlockedName function
Whether the two-word name first second is blocked: a blocked word,
a blocked bigram, a blocked substring created by the join, or blocked
initials.
Implementation
bool isBlockedName(String first, String second) {
final a = first.toLowerCase();
final b = second.toLowerCase();
if (blockedWords.contains(a) || blockedWords.contains(b)) return true;
if (a == b) return true;
for (final (x, y) in blockedBigrams) {
bool match(String p, String q) =>
(x.isEmpty || p == x) && (y.isEmpty || q == y);
if (match(a, b) || match(b, a)) return true;
}
for (final (p, q) in [(a, b), (b, a)]) {
final joined = '$p$q';
final boundary = p.length;
for (final bad in blockedJoinSubstrings) {
// Created by the join iff an occurrence spans the boundary.
final from = boundary - bad.length + 1;
final start = from < 0 ? 0 : from;
final i = joined.indexOf(bad, start);
if (i >= 0 && i < boundary) return true;
}
}
final initials = '${first[0]}${second[0]}'.toUpperCase();
return blockedInitials.contains(initials);
}