on master help sign in
Replace types with their more descriptive synonyms
5cf629cBryan O'Sullivan
Data/Text/Encoding/Error.hs+7−3
@@ -62,7 +62,11 @@ import Numeric (showHex)
62-- use the description provided to construct a more helpful error
62-- use the description provided to construct a more helpful error
63-- report.
63-- report.
64type OnError a b = String -> Maybe a -> Maybe b
64type OnError a b = String -> Maybe a -> Maybe b
65+
66+-- | A handler for a decoding error.
65type OnDecodeError = OnError Word8 Char
67type OnDecodeError = OnError Word8 Char
68+
69+-- | A handler for an encoding error.
66type OnEncodeError = OnError Char Word8
70type OnEncodeError = OnError Char Word8
67
71
68-- | An exception type for representing Unicode encoding errors.
72-- | An exception type for representing Unicode encoding errors.
@@ -91,16 +95,16 @@ instance Show UnicodeException where
91instance Exception UnicodeException
95instance Exception UnicodeException
92
96
93-- | Throw a 'UnicodeException' if decoding fails.
97-- | Throw a 'UnicodeException' if decoding fails.
94−strictDecode :: OnError Word8 Char
98+strictDecode :: OnDecodeError
95strictDecode desc c = throw (DecodeError desc c)
99strictDecode desc c = throw (DecodeError desc c)
96
100
97-- | Replace an invalid input byte with the Unicode replacement
101-- | Replace an invalid input byte with the Unicode replacement
98-- character U+FFFD.
102-- character U+FFFD.
99−lenientDecode :: OnError Word8 Char
103+lenientDecode :: OnDecodeError
100lenientDecode _ _ = Just '\xfffd'
104lenientDecode _ _ = Just '\xfffd'
101
105
102-- | Throw a 'UnicodeException' if encoding fails.
106-- | Throw a 'UnicodeException' if encoding fails.
103−strictEncode :: OnError Char Word8
107+strictEncode :: OnEncodeError
104strictEncode desc c = throw (EncodeError desc c)
108strictEncode desc c = throw (EncodeError desc c)
105
109
106-- | Ignore an invalid input, substituting nothing in the output.
110-- | Ignore an invalid input, substituting nothing in the output.