on master help sign in
Tidy up and test UTF-16BE

--HG-- extra : convert_revision : d75139cd10057e4229966a91b73103f7b4094572

commit94df678b016f7cfe9ca9d35e9e8106da170315b5 authorBryan O'Sullivan <bos@serpentine.com> dateTue 24 Feb 2009, 05:49 (18 years ago) parent7e1dd4e
2 files changed+10−8
Data/Text/Encoding/Fusion.hs+8−8 tests/Properties.hs+2
Data/Text/Encoding/Fusion.hs+8−8
@@ -200,15 +200,15 @@ restreamUtf8 (Stream next0 s0 len) =
200200
201201restreamUtf16BE :: Stream Char -> Stream Word8
202202restreamUtf16BE (Stream next0 s0 len) =
203− Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
203+ Stream next (T4 s0 N N N) (len*2)
204204 where
205205 {-# INLINE next #-}
206− next (T4 (Just s) Nothing Nothing Nothing) = case next0 s of
206+ next (T4 s N N N) = case next0 s of
207207 Done -> Done
208− Skip s' -> Skip (T4 (Just s') Nothing Nothing Nothing)
208+ Skip s' -> Skip (T4 s' N N N)
209209 Yield x xs
210− | n < 0x10000 -> Yield (fromIntegral $ shiftR n 8) (T4 (Just xs) (Just (fromIntegral n)) Nothing Nothing)
211− | otherwise -> Yield c1 (T4 (Just xs) (Just c2) (Just c3) (Just c4))
210+ | n < 0x10000 -> Yield (fromIntegral $ shiftR n 8) (T4 xs (J (fromIntegral n)) N N)
211+ | otherwise -> Yield c1 (T4 xs (J c2) (J c3) (J c4))
212212 where
213213 n = ord x
214214 n1 = n - 0x10000
@@ -217,9 +217,9 @@ restreamUtf16BE (Stream next0 s0 len) =
217217 n2 = n1 .&. 0x3FF
218218 c3 = fromIntegral (shiftR n2 8 + 0xDC)
219219 c4 = fromIntegral n2
220− next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
221− next (T4 (Just s) (Just x2) x3 Nothing) = Yield x2 (T4 (Just s) x3 Nothing Nothing)
222− next (T4 (Just s) (Just x2) x3 x4) = Yield x2 (T4 (Just s) x3 x4 Nothing)
220+ next (T4 s (J x2) N N) = Yield x2 (T4 s N N N)
221+ next (T4 s (J x2) x3 N) = Yield x2 (T4 s x3 N N)
222+ next (T4 s (J x2) x3 x4) = Yield x2 (T4 s x3 x4 N)
223223 next _ = internalError "restreamUtf16BE"
224224{-# INLINE restreamUtf16BE #-}
225225
tests/Properties.hs+2
@@ -42,6 +42,7 @@ prop_ascii t = E.decodeASCII (E.encodeASCII a) == a
4242 where a = T.map (\c -> chr (ord c `mod` 128)) t
4343prop_utf8 = (E.decodeUtf8 . E.encodeUtf8) `eq` id
4444prop_utf16LE = (E.decodeUtf16LE . E.encodeUtf16LE) `eq` id
45+prop_utf16BE = (E.decodeUtf16BE . E.encodeUtf16BE) `eq` id
4546
4647-- Do two functions give the same answer?
4748eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
@@ -233,6 +234,7 @@ tests = [
233234 ("prop_ascii", mytest prop_ascii),
234235 ("prop_utf8", mytest prop_utf8),
235236 ("prop_utf16LE", mytest prop_utf16LE),
237+ ("prop_utf16BE", mytest prop_utf16BE),
236238
237239 ("prop_cons", mytest prop_cons),
238240 ("prop_snoc", mytest prop_snoc),