Commits

Bryan O'Sullivan  committed c9864f1

Tidy up and test UTF-16BE

  • Participants
  • Parent commits f06e804

Comments (0)

Files changed (2)

File Data/Text/Encoding/Fusion.hs

 
 restreamUtf16BE :: Stream Char -> Stream Word8
 restreamUtf16BE (Stream next0 s0 len) =
-    Stream next (T4 (Just s0) Nothing Nothing Nothing) (len*2)
+    Stream next (T4 s0 N N N) (len*2)
     where
       {-# INLINE next #-}
-      next (T4 (Just s) Nothing Nothing Nothing) = case next0 s of
+      next (T4 s N N N) = case next0 s of
           Done -> Done
-          Skip s' -> Skip (T4 (Just s') Nothing Nothing Nothing)
+          Skip s' -> Skip (T4 s' N N N)
           Yield x xs
-              | n < 0x10000 -> Yield (fromIntegral $ shiftR n 8) (T4 (Just xs) (Just (fromIntegral n)) Nothing Nothing)
-              | otherwise   -> Yield c1                          (T4 (Just xs) (Just c2) (Just c3) (Just c4))
+              | n < 0x10000 -> Yield (fromIntegral $ shiftR n 8) (T4 xs (J (fromIntegral n)) N N)
+              | otherwise   -> Yield c1                          (T4 xs (J c2) (J c3) (J c4))
               where
                 n  = ord x
                 n1 = n - 0x10000
                 n2 = n1 .&. 0x3FF
                 c3 = fromIntegral (shiftR n2 8 + 0xDC)
                 c4 = fromIntegral n2
-      next (T4 (Just s) (Just x2) Nothing Nothing) = Yield x2 (T4 (Just s) Nothing Nothing Nothing)
-      next (T4 (Just s) (Just x2) x3 Nothing)      = Yield x2 (T4 (Just s) x3 Nothing Nothing)
-      next (T4 (Just s) (Just x2) x3 x4)           = Yield x2 (T4 (Just s) x3 x4 Nothing)
+      next (T4 s (J x2) N N)   = Yield x2 (T4 s N N N)
+      next (T4 s (J x2) x3 N)  = Yield x2 (T4 s x3 N N)
+      next (T4 s (J x2) x3 x4) = Yield x2 (T4 s x3 x4 N)
       next _ = internalError "restreamUtf16BE"
 {-# INLINE restreamUtf16BE #-}
 

File tests/Properties.hs

     where a            = T.map (\c -> chr (ord c `mod` 128)) t
 prop_utf8              = (E.decodeUtf8 . E.encodeUtf8) `eq` id
 prop_utf16LE           = (E.decodeUtf16LE . E.encodeUtf16LE) `eq` id
+prop_utf16BE           = (E.decodeUtf16BE . E.encodeUtf16BE) `eq` id
 
 -- Do two functions give the same answer?
 eq :: (Eq a) => (t -> a) -> (t -> a) -> t -> Bool
   ("prop_ascii", mytest prop_ascii),
   ("prop_utf8", mytest prop_utf8),
   ("prop_utf16LE", mytest prop_utf16LE),
+  ("prop_utf16BE", mytest prop_utf16BE),
 
   ("prop_cons", mytest prop_cons),
   ("prop_snoc", mytest prop_snoc),