validatePayload method

void validatePayload()

Implementation

void validatePayload() {
  if (insertedBytes.length != insertedByteLength) {
    throw FormatException(
      'Inserted UTF-8 length ${insertedBytes.length} does not match '
      '$insertedByteLength-byte edit extent',
    );
  }
  final start = startUtf16;
  final oldEnd = oldEndUtf16;
  final newEnd = newEndUtf16;
  if (start != null && oldEnd != null && oldEnd < start) {
    throw const FormatException('oldEndUtf16 precedes startUtf16');
  }
  if (start != null && newEnd != null && newEnd < start) {
    throw const FormatException('newEndUtf16 precedes startUtf16');
  }
  if (start != null &&
      newEnd != null &&
      newEnd - start != insertedText.length) {
    throw FormatException(
      'Inserted UTF-16 length ${insertedText.length} does not match '
      '${newEnd - start}-code-unit edit extent',
    );
  }
}