substring method
Returns a substring of the data source starting at offset start and
ending at offset end.
Throws an exception if the specified offsets start or end are outside
the valid range.
The start and end must be specified in units defined by the
specific reader.
Implementation
@override
String substring(int start, [int? end]) {
if (end != null && start > end) {
throw RangeError.range(start, 0, end, 'start');
}
var index = start;
var readDataSize = 0;
if (end != null) {
if (start > end) {
throw RangeError.range(start, 0, end, 'start');
}
if (end - start == 0) {
_lastIndex = -1;
_readDataSize = 0;
return '';
}
}
end ??= length;
final charCodes = <int>[];
while (index < end) {
final c = _read(index);
charCodes.add(c);
index += _readDataSize;
readDataSize += _readDataSize;
}
_lastIndex = -1;
_readDataSize = readDataSize;
return String.fromCharCodes(charCodes);
}