toUtf8 static method

Implementation

static Pointer<Utf8NullTerminated> toUtf8(String s) {
  final bytes = Utf8Encoder().convert(s);
  final ptr = calloc<Utf8NullTerminated>(bytes.length + 1);
  for (var i = 0; i < bytes.length; i++) {
    ptr.elementAt(i).ref.char = bytes[i];
  }
  // Add the terminator '\0'
  ptr.elementAt(bytes.length).ref.char = 0;
  return ptr;
}