text
text copied to clipboard
add Data.Text.Foreign.peekCString?
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.
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.