stringToNativeChar function

Pointer<Utf8> stringToNativeChar(
  1. String str,
  2. {Allocator allocator = calloc}
)

Implementation

Pointer<Utf8> stringToNativeChar(String str, {Allocator allocator = calloc}) {
  final units = utf8.encode(str);
  final result = allocator<Uint8>(units.length + 1);
  final nativeString = result.asTypedList(units.length + 1);
  nativeString.setAll(0, units);
  nativeString[units.length] = 0;
  return result.cast();
}