equalsString method

bool equalsString(
  1. String other
)

Whether the decoded text equals other, without allocating.

Implementation

bool equalsString(String other) {
  var i = start;
  var j = 0;
  while (i < end && j < other.length) {
    final unit = other.codeUnitAt(j);
    if (unit < 0x80) {
      if (bytes[i] != unit) return false;
      i++;
      j++;
      continue;
    }
    final (rune, bytesUsed) = _runeAt(bytes, i, end);
    if (rune < 0) return false;
    final otherRune = unit >= 0xD800 && unit <= 0xDBFF
        ? 0x10000 +
              ((unit - 0xD800) << 10) +
              (other.codeUnitAt(j + 1) - 0xDC00)
        : unit;
    if (rune != otherRune) return false;
    i += bytesUsed;
    j += otherRune > 0xFFFF ? 2 : 1;
  }
  return i == end && j == other.length;
}