dart-lang / dart-lang/native

How to treat Array<ffi.Char>?

Open
#919 0 comments 0 reactions 0 assignees View on GitHub
package:ffi
Dominant language
Dart
Stars
275
Forks
144
Avg merge
2d 10h
Merged PRs (30d)
47

Description

Hello team! I'm having an issue with the Array type that I couldn't find an answer to in previous issues.

I'm bridging over a type of:
```
char cFileName[1024];

// to

@ffi.Array.multi([1024])
external ffi.Array cFileName;
```

I'm wondering how I should be converting that to a string. I'm currently doing it with:
```dart
return utf8.decode(_data.ref.spreadCFileName().toList(), allowMalformed: false);

Iterable spreadCFileName() sync* {
for (var i = 0; i < MAX_PATH; i++) {
final value = cFileName[i];
if (value == 0) {
return;
}

yield value;
}
}
```

This works, but fails to handle accents like in `Charité` which returns an error of: `Unhandled Exception: FormatException: Invalid UTF-8 byte (at offset 16)` unless I set `allowMalformed: true`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.