module Text.XML.HXT.DOM.UTF8Decoding (
decodeUtf8,
decodeUtf8EmbedErrors,
)
where
import qualified Data.Char.UTF8 as UTF8
import Data.Word (Word8)
decodeUtf8 :: String -> (String, [String])
decodeUtf8 str
= (res, map (uncurry toErrStr) errs)
where
(res, errs) = UTF8.decode . stringToByteString $ str
decodeUtf8EmbedErrors :: String -> [Either String Char]
decodeUtf8EmbedErrors str
= map (either (Left . uncurry toErrStr) Right) $
UTF8.decodeEmbedErrors $ stringToByteString $ str
stringToByteString :: String -> [Word8]
stringToByteString = map (toEnum . fromEnum)
toErrStr :: UTF8.Error -> Int -> String
toErrStr err pos
= " at input position " ++ show pos ++ ": " ++ show err