toDartString method

String toDartString({
  1. int? length,
})

Converts this UTF-16 encoded string to a Dart string.

Decodes the UTF-16 code units of this zero-terminated code unit array as Unicode code points and creates a Dart string containing those code points.

If length is provided, zero-termination is ignored and the result can contain NUL characters.

If length is not provided, the returned string is the string up til but not including the first NUL character.

Implementation

String toDartString({int? length}) {
  _ensureNotNullptr('toDartString');
  final codeUnits = cast<Uint16>();
  if (length == null) {
    return _toUnknownLengthString(codeUnits);
  } else {
    RangeError.checkNotNegative(length, 'length');
    return _toKnownLengthString(codeUnits, length);
  }
}