dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
155 stars 43 forks source link

Add `Utf8`/`Utf16` methods for non-zero terminated strings #933

Open robertbastian opened 11 months ago

robertbastian commented 11 months ago

I find it odd that this package only provides support for null-terminated strings with the Utf8 and Utf16 marker types.

It's quite common these days to not use zero terminated strings, but to use string views which are ptr + size. This is done for example in Rust (&str) and C++ (std::string_view). Advantages over null-terminated strings are constant time length and no buffer overflows if you lose the \0.

dcharkes commented 11 months ago

toNativeUtf8NonZeroTerminated() would need some kind of different API most likely one that returns a record: both the pointer and the length. (Names TBD.)