Converts the UTF-8 codeUnits
(a list of unsigned 8-bit integers) to the corresponding string.
Uses the code units from start
to, but no including, end
. If end
is omitted, it defaults to codeUnits.length
.
If the codeUnits
start with the encoding of a unicodeBomCharacterRune, that character is discarded.
String convert(List<int> codeUnits, [int start = 0, int end]) { // Allow the implementation to intercept and specialize based on the type // of codeUnits. var result = _convertIntercepted(_allowMalformed, codeUnits, start, end); if (result != null) { return result; } var length = codeUnits.length; end = RangeError.checkValidRange(start, end, length); // Fast case for ASCII strings avoids StringBuffer/_Utf8Decoder. int oneBytes = _scanOneByteCharacters(codeUnits, start, end); StringBuffer buffer; bool isFirstCharacter = true; if (oneBytes > 0) { var firstPart = String.fromCharCodes(codeUnits, start, start + oneBytes); start += oneBytes; if (start == end) { return firstPart; } buffer = StringBuffer(firstPart); isFirstCharacter = false; } buffer ??= StringBuffer(); var decoder = _Utf8Decoder(buffer, _allowMalformed); decoder._isFirstCharacter = isFirstCharacter; decoder.convert(codeUnits, start, end); decoder.flush(codeUnits, end); return buffer.toString(); }
© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.5.0/dart-convert/Utf8Decoder/convert.html