@hackage text-conversions0.2.0
Safe conversions between textual types
Categories
License
ISC
Maintainer
lexi.lambda@gmail.com
Links
Versions
Installation
Dependencies (4)
- base >=4.7 && <5
- bytestring
- errors
- text Show all…
Dependents (29)
@hackage/rfc, @hackage/cj-token, @hackage/hs-aws-lambda, @hackage/string-interpolate, @hackage/snowchecked, @hackage/sugar, Show all…
text-conversions
This is a small library to ease the pain when converting between the many different string types in Haskell. Unlike some other libraries that attempt to solve the same problem, text-conversions is:
-
Safe. This library treats binary data (aka
ByteString) like binary data, and it does not assume a particular encoding, nor does it ever throw exceptions when failing to decode. It does, however, provide failable conversions between binary data and textual data through the same exact interface as conversions between purely textual data. -
Extensible. It’s easy to add or derive your own instances of the typeclasses to use your own types through the same interface.
Here’s an example of using text-conversions to convert between textual types:
> convertText ("hello" :: String) :: Text
"hello"
And here’s an example of converting from UTF-8 encoded binary data to a textual format:
> convertText (UTF8 ("hello" :: ByteString)) :: Maybe Text
Just "hello"
> convertText (UTF8 ("\xc3\x28" :: ByteString)) :: Maybe Text
Nothing