简体   繁体   中英

Haskell Word8 to Text format

我正在寻找从Word8转换为Text的最佳方法,问题是将runChildrenWithText函数用于Heist需要文本输入进行绑定,但是getParam功能返回的ByteStrings可以转换为Word8,但不能转换为这两种格式的Text ,因此我在决定从这里出发时遇到了麻烦,对于解决此问题的最佳方法的任何帮助都将受到赞赏。

The Data.Text.Encodings package has many methods of converting ByteString s to Text . Note that it's possible for a ByteString to Text encoding to fail (say, you are assuming the ByteString contains UTF-8 data but it actually doesn't) so this is a more complex process than just convert :: ByteString -> Text .

To wit, decodeUtf8 :: ByteString -> Text will throw impure exceptions, so decodeUtf8' :: ByteString -> Either UnicodeException Text may be preferable if there's any chance of a decode failure.

You can also build more sophisticated decode failure handler schemes using decodeUtf8With :: OnDecodeError -> ByteString -> Text and Data.Text.Encodings.Error .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM