text-conversions: Safe conversions between textual types

[ data, library ] [ Propose Tags ]

Safe conversions between textual types


[Skip to Readme]

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.3.1.1
Change log CHANGELOG.md
Dependencies base (>=4.7 && <5), bytestring, errors, text [details]
License ISC
Author Alexis King
Maintainer lexi.lambda@gmail.com
Category Data
Home page https://github.com/cjdev/text-conversions#readme
Bug tracker https://github.com/cjdev/text-conversions/issues
Source repo head: git clone https://github.com/cjdev/text-conversions
Uploaded by lexi_lambda at 2016-05-25T18:05:27Z
Distributions Arch:0.3.1.1, Debian:0.3.0, Fedora:0.3.1.1, LTSHaskell:0.3.1.1, NixOS:0.3.1.1, Stackage:0.3.1.1, openSUSE:0.3.1.1
Reverse Dependencies 28 direct, 339 indirect [details]
Downloads 20923 total (191 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-11-25 [all 1 reports]

Readme for text-conversions-0.2.0

[back to package description]

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

For more details, see the documentation on Hackage.