Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to treat Array<ffi.Char>? #919

Open
dcvz opened this issue Feb 1, 2023 · 1 comment
Open

How to treat Array<ffi.Char>? #919

dcvz opened this issue Feb 1, 2023 · 1 comment

Comments

@dcvz
Copy link

dcvz commented Feb 1, 2023

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<ffi.Char> cFileName;

I'm wondering how I should be converting that to a string. I'm currently doing it with:

return utf8.decode(_data.ref.spreadCFileName().toList(), allowMalformed: false);

Iterable<int> 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

This issue is being transferred. Timeline may not be complete until it finishes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants