agreement static method

LabelAgreement agreement(
  1. String target,
  2. String label
)

How a control's own label relates to the requested target label.

Implementation

static LabelAgreement agreement(String target, String label) {
  final t = tokens(target);
  final l = tokens(label);
  if (t.isEmpty || l.isEmpty) return LabelAgreement.empty;
  if (squash(t.join()) == squash(l.join())) return LabelAgreement.exact;
  final tInL = _subset(t, l);
  final lInT = _subset(l, t);
  if (tInL && lInT) return LabelAgreement.exact;
  if (lInT) return LabelAgreement.narrower;
  if (tInL) {
    // Any meaningful label token BEFORE the first requested token is a
    // qualifier naming a different entity ("Nominee Name").
    final first = l.indexWhere((x) => t.any((y) => tokenEq(x, y)));
    return first > 0 ? LabelAgreement.qualified : LabelAgreement.broader;
  }
  return LabelAgreement.mismatch;
}