From 0194bd1aa23f3c93c9fea3f6acdf5b968c024886 Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Mon, 6 Jul 2009 13:33:03 +0000 Subject: [PATCH] Use the result of writeCharBuf This only makes a difference when CHARBUF_UTF16 is in use, which it normally isn't. I suspect CHARBUF_UTF16 doesn't currently work for other reasons (CHARBUF_UTF16 was an experiment before I wrote the GHC.IO.Encoding.UTF* codecs), but this patch at least makes it slightly closer to working. --- GHC/IO/Encoding/UTF16.hs | 16 ++++++++-------- GHC/IO/Encoding/UTF32.hs | 8 ++++---- GHC/IO/Encoding/UTF8.hs | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/GHC/IO/Encoding/UTF16.hs b/GHC/IO/Encoding/UTF16.hs index a5a6b62..f7d7cb0 100644 --- a/GHC/IO/Encoding/UTF16.hs +++ b/GHC/IO/Encoding/UTF16.hs @@ -195,15 +195,15 @@ utf16be_decode c1 <- readWord8Buf iraw (ir+1) let x1 = fromIntegral c0 `shiftL` 8 + fromIntegral c1 if validate1 x1 - then do writeCharBuf oraw ow (unsafeChr (fromIntegral x1)) - loop (ir+2) (ow+1) + then do ow' <- writeCharBuf oraw ow (unsafeChr (fromIntegral x1)) + loop (ir+2) ow' else if iw - ir < 4 then done ir ow else do c2 <- readWord8Buf iraw (ir+2) c3 <- readWord8Buf iraw (ir+3) let x2 = fromIntegral c2 `shiftL` 8 + fromIntegral c3 if not (validate2 x1 x2) then invalid else do - writeCharBuf oraw ow (chr2 x1 x2) - loop (ir+4) (ow+1) + ow' <- writeCharBuf oraw ow (chr2 x1 x2) + loop (ir+4) ow' where invalid = if ir > ir0 then done ir ow else ioe_decodingError @@ -227,15 +227,15 @@ utf16le_decode c1 <- readWord8Buf iraw (ir+1) let x1 = fromIntegral c1 `shiftL` 8 + fromIntegral c0 if validate1 x1 - then do writeCharBuf oraw ow (unsafeChr (fromIntegral x1)) - loop (ir+2) (ow+1) + then do ow' <- writeCharBuf oraw ow (unsafeChr (fromIntegral x1)) + loop (ir+2) ow' else if iw - ir < 4 then done ir ow else do c2 <- readWord8Buf iraw (ir+2) c3 <- readWord8Buf iraw (ir+3) let x2 = fromIntegral c3 `shiftL` 8 + fromIntegral c2 if not (validate2 x1 x2) then invalid else do - writeCharBuf oraw ow (chr2 x1 x2) - loop (ir+4) (ow+1) + ow' <- writeCharBuf oraw ow (chr2 x1 x2) + loop (ir+4) ow' where invalid = if ir > ir0 then done ir ow else ioe_decodingError diff --git a/GHC/IO/Encoding/UTF32.hs b/GHC/IO/Encoding/UTF32.hs index 17a817e..a7c3054 100644 --- a/GHC/IO/Encoding/UTF32.hs +++ b/GHC/IO/Encoding/UTF32.hs @@ -189,8 +189,8 @@ utf32be_decode c3 <- readWord8Buf iraw (ir+3) let x1 = chr4 c0 c1 c2 c3 if not (validate x1) then invalid else do - writeCharBuf oraw ow x1 - loop (ir+4) (ow+1) + ow' <- writeCharBuf oraw ow x1 + loop (ir+4) ow' where invalid = if ir > ir0 then done ir ow else ioe_decodingError @@ -215,8 +215,8 @@ utf32le_decode c3 <- readWord8Buf iraw (ir+3) let x1 = chr4 c3 c2 c1 c0 if not (validate x1) then invalid else do - writeCharBuf oraw ow x1 - loop (ir+4) (ow+1) + ow' <- writeCharBuf oraw ow x1 + loop (ir+4) ow' where invalid = if ir > ir0 then done ir ow else ioe_decodingError diff --git a/GHC/IO/Encoding/UTF8.hs b/GHC/IO/Encoding/UTF8.hs index 99928e0..34cca18 100644 --- a/GHC/IO/Encoding/UTF8.hs +++ b/GHC/IO/Encoding/UTF8.hs @@ -68,29 +68,29 @@ utf8_decode c0 <- readWord8Buf iraw ir case c0 of _ | c0 <= 0x7f -> do - writeCharBuf oraw ow (unsafeChr (fromIntegral c0)) - loop (ir+1) (ow+1) + ow' <- writeCharBuf oraw ow (unsafeChr (fromIntegral c0)) + loop (ir+1) ow' | c0 >= 0xc0 && c0 <= 0xdf -> if iw - ir < 2 then done ir ow else do c1 <- readWord8Buf iraw (ir+1) if (c1 < 0x80 || c1 >= 0xc0) then invalid else do - writeCharBuf oraw ow (chr2 c0 c1) - loop (ir+2) (ow+1) + ow' <- writeCharBuf oraw ow (chr2 c0 c1) + loop (ir+2) ow' | c0 >= 0xe0 && c0 <= 0xef -> if iw - ir < 3 then done ir ow else do c1 <- readWord8Buf iraw (ir+1) c2 <- readWord8Buf iraw (ir+2) if not (validate3 c0 c1 c2) then invalid else do - writeCharBuf oraw ow (chr3 c0 c1 c2) - loop (ir+3) (ow+1) + ow' <- writeCharBuf oraw ow (chr3 c0 c1 c2) + loop (ir+3) ow' | c0 >= 0xf0 -> if iw - ir < 4 then done ir ow else do c1 <- readWord8Buf iraw (ir+1) c2 <- readWord8Buf iraw (ir+2) c3 <- readWord8Buf iraw (ir+3) if not (validate4 c0 c1 c2 c3) then invalid else do - writeCharBuf oraw ow (chr4 c0 c1 c2 c3) - loop (ir+4) (ow+1) + ow' <- writeCharBuf oraw ow (chr4 c0 c1 c2 c3) + loop (ir+4) ow' | otherwise -> invalid where -- 1.7.10.4