on master help sign in
Tidy up Utf8 a little
c84c559Bryan O'Sullivan
Data/Text/Encoding/Utf8.hs+11−16
@@ -48,7 +48,7 @@ between :: Word8 -- ^ byte to check
48between x y z = x >= y && x <= z
48between x y z = x >= y && x <= z
49{-# INLINE between #-}
49{-# INLINE between #-}
50
50
51−ord2 :: Char -> (Word8,Word8)
51+ord2 :: Char -> (Word8,Word8)
52ord2 c =
52ord2 c =
53#if defined(ASSERTS)
53#if defined(ASSERTS)
54 assert (n >= 0x80 && n <= 0x07ff)
54 assert (n >= 0x80 && n <= 0x07ff)
@@ -59,7 +59,7 @@ ord2 c =
59 x1 = fromIntegral $ (n `shiftR` 6) + 0xC0
59 x1 = fromIntegral $ (n `shiftR` 6) + 0xC0
60 x2 = fromIntegral $ (n .&. 0x3F) + 0x80
60 x2 = fromIntegral $ (n .&. 0x3F) + 0x80
61
61
62−ord3 :: Char -> (Word8,Word8,Word8)
62+ord3 :: Char -> (Word8,Word8,Word8)
63ord3 c =
63ord3 c =
64#if defined(ASSERTS)
64#if defined(ASSERTS)
65 assert (n >= 0x0800 && n <= 0xffff)
65 assert (n >= 0x0800 && n <= 0xffff)
@@ -71,7 +71,7 @@ ord3 c =
71 x2 = fromIntegral $ ((n `shiftR` 6) .&. 0x3F) + 0x80
71 x2 = fromIntegral $ ((n `shiftR` 6) .&. 0x3F) + 0x80
72 x3 = fromIntegral $ (n .&. 0x3F) + 0x80
72 x3 = fromIntegral $ (n .&. 0x3F) + 0x80
73
73
74−ord4 :: Char -> (Word8,Word8,Word8,Word8)
74+ord4 :: Char -> (Word8,Word8,Word8,Word8)
75ord4 c =
75ord4 c =
76#if defined(ASSERTS)
76#if defined(ASSERTS)
77 assert (n >= 0x10000)
77 assert (n >= 0x10000)
@@ -84,7 +84,7 @@ ord4 c =
84 x3 = fromIntegral $ ((n `shiftR` 6) .&. 0x3F) + 0x80
84 x3 = fromIntegral $ ((n `shiftR` 6) .&. 0x3F) + 0x80
85 x4 = fromIntegral $ (n .&. 0x3F) + 0x80
85 x4 = fromIntegral $ (n .&. 0x3F) + 0x80
86
86
87−chr2 :: Word8 -> Word8 -> Char
87+chr2 :: Word8 -> Word8 -> Char
88chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
88chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
89 where
89 where
90 !y1# = word2Int# x1#
90 !y1# = word2Int# x1#
@@ -93,7 +93,7 @@ chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
93 !z2# = y2# -# 0x80#
93 !z2# = y2# -# 0x80#
94{-# INLINE chr2 #-}
94{-# INLINE chr2 #-}
95
95
96−chr3 :: Word8 -> Word8 -> Word8 -> Char
96+chr3 :: Word8 -> Word8 -> Word8 -> Char
97chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
97chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
98 where
98 where
99 !y1# = word2Int# x1#
99 !y1# = word2Int# x1#
@@ -118,20 +118,17 @@ chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
118 !z4# = y4# -# 0x80#
118 !z4# = y4# -# 0x80#
119{-# INLINE chr4 #-}
119{-# INLINE chr4 #-}
120
120
121−validate1 :: Word8 -> Bool
121+validate1 :: Word8 -> Bool
122validate1 x1 = x1 <= 0x7F
122validate1 x1 = x1 <= 0x7F
123{-# INLINE validate1 #-}
123{-# INLINE validate1 #-}
124
124
125−validate2 :: Word8 -> Word8 -> Bool
125+validate2 :: Word8 -> Word8 -> Bool
126validate2 x1 x2 = between x1 0xC2 0xDF && between x2 0x80 0xBF
126validate2 x1 x2 = between x1 0xC2 0xDF && between x2 0x80 0xBF
127{-# INLINE validate2 #-}
127{-# INLINE validate2 #-}
128
128
129−validate3 :: Word8 -> Word8 -> Word8 -> Bool
129+validate3 :: Word8 -> Word8 -> Word8 -> Bool
130{-# INLINE validate3 #-}
130{-# INLINE validate3 #-}
131−validate3 x1 x2 x3 = validate3_1 ||
131+validate3 x1 x2 x3 = validate3_1 || validate3_2 || validate3_3 || validate3_4
132− validate3_2 ||
133− validate3_3 ||
134− validate3_4
135 where
132 where
136 validate3_1 = (x1 == 0xE0) &&
133 validate3_1 = (x1 == 0xE0) &&
137 between x2 0xA0 0xBF &&
134 between x2 0xA0 0xBF &&
@@ -146,11 +143,9 @@ validate3 x1 x2 x3 = validate3_1 ||
146 between x2 0x80 0xBF &&
143 between x2 0x80 0xBF &&
147 between x3 0x80 0xBF
144 between x3 0x80 0xBF
148
145
149−validate4 :: Word8 -> Word8 -> Word8 -> Word8 -> Bool
146+validate4 :: Word8 -> Word8 -> Word8 -> Word8 -> Bool
150{-# INLINE validate4 #-}
147{-# INLINE validate4 #-}
151−validate4 x1 x2 x3 x4 = validate4_1 ||
148+validate4 x1 x2 x3 x4 = validate4_1 || validate4_2 || validate4_3
152− validate4_2 ||
153− validate4_3
154 where
149 where
155 validate4_1 = x1 == 0xF0 &&
150 validate4_1 = x1 == 0xF0 &&
156 between x2 0x90 0xBF &&
151 between x2 0x90 0xBF &&