mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-09 20:39:35 +00:00
25 lines
617 B
Dart
25 lines
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;
|
||
|
}
|
||
|
}
|