mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 12:09:43 +00:00
25 lines
No EOL
617 B
Dart
25 lines
No EOL
617 B
Dart
import 'dart:convert';
|
|
import 'dart:ffi';
|
|
|
|
import 'package:ffi/ffi.dart';
|
|
|
|
extension Utf8Pointer on Pointer<Utf8> {
|
|
String toDartStringAllowingMalformed({int? length}) {
|
|
//_ensureNotNullptr('toDartString');
|
|
final codeUnits = cast<Uint8>();
|
|
if (length != null) {
|
|
RangeError.checkNotNegative(length, 'length');
|
|
} else {
|
|
length = _length(codeUnits);
|
|
}
|
|
return utf8.decode(codeUnits.asTypedList(length), allowMalformed: true);
|
|
}
|
|
|
|
static int _length(Pointer<Uint8> codeUnits) {
|
|
var length = 0;
|
|
while (codeUnits[length] != 0) {
|
|
length++;
|
|
}
|
|
return length;
|
|
}
|
|
} |