asCharP method

Pointer<Char> asCharP({
  1. Allocator allocator = malloc,
  2. Encoding? encoding,
})

Returns * char

Implementation

Pointer<Char> asCharP({Allocator allocator = malloc, Encoding? encoding}) {
  final units = encoding != null ? encoding.encode(this) : utf8.encode(this);

  final Pointer<Uint8> result = allocator<Uint8>(units.length + 1);
  final Uint8List nativeString = result.asTypedList(units.length + 1);
  nativeString.setAll(0, units);
  nativeString[units.length] = 0;
  return result.cast();
}