differenceEncoded static method

int differenceEncoded(
  1. String? e1,
  2. String? e2
)

Returns the number of characters that are the same in the e1 and e2 encoded strings.

Despite the name, this is actually a measure of similarity. This naming is consistent with the SQL DIFFERENCE function definition.

Implementation

static int differenceEncoded(final String? e1, final String? e2) {
  if (e1 == null || e1.isEmpty || e2 == null || e2.isEmpty) {
    return 0;
  }

  var iterator1 = e1.codeUnits.iterator;
  var iterator2 = e2.codeUnits.iterator;

  var diff = 0;
  while (iterator1.moveNext() && iterator2.moveNext()) {
    if (iterator1.current == iterator2.current) {
      diff++;
    }
  }

  return diff;
}