text icon indicating copy to clipboard operation
text copied to clipboard

add Data.Text.Foreign.peekCString?

Open chessai opened this issue 6 years ago • 2 comments

we already have peekCStringLen:

peekCStringLen :: CStringLen -> IO Text
peekCStringLen cs = do
  bs <- unsafePackCStringLen cs
  return $! decodeUtf8 bs

would it make sense to have peekCString?

peekCString :: CString -> IO Text
peekCString cs = do
  bs <- unsafePackCString cs
  return $! decodeUtf8 bs

It just calls a different function from Data.ByteString.Unsafe. It seems like Data.Text.Foreign would be a natural home for this given that peekCStringLen is already there.

chessai avatar Nov 07 '18 16:11 chessai

I know this is quite a few years old, but I bumped into this as well. It's very odd that peekCString is missing, requiring most strings to either be marshalled via String or do an explicit strlen (probably on the C side, because I don't see a convenient one in Haskell) before converting to Text.

cdsmith avatar Sep 07 '22 04:09 cdsmith