tryParseAsciiFloat64 function
Parses UTF-8 float text without allocating a String on the ASCII path.
Falls back to utf8.decode + double.tryParse for non-ASCII or formats
the fast path does not cover. Returns null when parsing fails.
Implementation
double? tryParseAsciiFloat64(Uint8List data) {
if (data.isEmpty) {
return null;
}
if (!isAsciiBytes(data)) {
final text = utf8.decode(data, allowMalformed: true);
return double.tryParse(text);
}
// Trim ASCII whitespace.
var start = 0;
var end = data.length;
while (start < end && _isAsciiSpace(data[start])) {
start++;
}
while (end > start && _isAsciiSpace(data[end - 1])) {
end--;
}
if (start >= end) {
return null;
}
final special = _tryParseAsciiFloatSpecial(data, start, end);
if (special != null) {
return special;
}
// Delegate to double.tryParse on a temporary Latin-1/ASCII string without
// UTF-8 scanning — fromCharCodes is cheaper than utf8.decode for ASCII.
return double.tryParse(
String.fromCharCodes(data, start, end),
);
}