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

Please provide peekUTF8CString and withUTF8CString #32

Closed
joshtriplett opened this issue Jul 4, 2012 · 3 comments · May be fixed by #254
Closed

Please provide peekUTF8CString and withUTF8CString #32

joshtriplett opened this issue Jul 4, 2012 · 3 comments · May be fixed by #254

Comments

@joshtriplett
Copy link

Most UNIX APIs work in UTF-8, not UTF-16. Rather than having to write wrappers that encode/decode UTF-8 and run ByteString's packCString and useAsCString functions (and the corresponding ...Len variants), please consider providing these functions directly in either Data.Text.Foreign or Data.Text.Encoding. Such wrappers would make c2hs bindings easier to write.

@bos
Copy link
Contributor

bos commented Jan 15, 2013

Happy to consider this, if you've an idea of what the APIs should specifically look like.

@joshtriplett
Copy link
Author

Same type signatures as peekCString and withCString, using the CString type, but accepting/producing UTF-8 respectively.

@joshtriplett
Copy link
Author

That commit added the Len variants, but not the peekUTF8CString and withUTF8CString functions needed to work with the much more common NUL-terminated UTF-8. Could you please add that pair of functions as well?

andersk added a commit to andersk/haskell-text that referenced this issue Mar 13, 2019
While here, document that `peekCStringLen`, `withCStringLen` are O(n)
as well.

Fixes haskell#32.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/haskell-text that referenced this issue Mar 13, 2019
Since NUL-terminated CString is much more common in foreign APIs than
CStringLen, one should not have to manually build these functions out
of `peekCStringLen`, `withCStringLen` (and perhaps get it wrong, like
I did in jgm/cmark-hs#13).

While here, document that `peekCStringLen`, `withCStringLen` are O(n)
as well.

Fixes haskell#32.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/haskell-text that referenced this issue Mar 13, 2019
Since NUL-terminated CString is much more common in foreign APIs than
CStringLen, one should not have to manually build these functions out
of `peekCStringLen`, `withCStringLen` (and perhaps get it wrong, like
I did in jgm/cmark-hs#13).

While here, document that `peekCStringLen`, `withCStringLen` are O(n)
as well.

Fixes haskell#32.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/haskell-text that referenced this issue Apr 6, 2021
Since NUL-terminated CString is much more common in foreign APIs than
CStringLen, one should not have to manually build these functions out
of `peekCStringLen`, `withCStringLen` (and perhaps get it wrong, like
I did in jgm/cmark-hs#13).

While here, document that `withCStringLen` is O(n) as well.

Fixes haskell#32.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants