Encoding and decoding functions for a variety of Unicode encodings can be found in the Data.Text.Encoding
module.
ghci> import Data.Text.Encoding
ghci> decodeUtf8 (encodeUtf8 "my text")
"my text"
Note that decodeUtf8
will throw an exception on invalid input. If you want to handle invalid UTF-8 yourself, use decodeUtf8With
.
ghci> decodeUtf8With (\errorDescription input -> Nothing) messyOutsideData