compareValuesCaseInsensitive function

int compareValuesCaseInsensitive(
  1. Object? a,
  2. Object? b
)

Case- and accent-insensitive variant of compareValues for text columns.

Folded equality is broken by the exact comparison, so the order stays total and 'Apple' and 'apple' keep a stable relative position. Filters must not use this - an equality test wants compareValuesFolded, where two values that differ only in case or accent compare equal.

Implementation

int compareValuesCaseInsensitive(Object? a, Object? b) {
  if (a is String && b is String) {
    final byFold = foldText(a).compareTo(foldText(b));
    // Fall back to the exact comparison so the order stays total.
    return byFold != 0 ? byFold : a.compareTo(b);
  }
  return compareValues(a, b);
}