From 529953686a9c3e5afcfe3b7b1b9090ebf84b3a80 Mon Sep 17 00:00:00 2001 From: Henning Guenther Date: Tue, 15 Jan 2008 17:39:24 -0800 Subject: [PATCH] Fixed UTF16 decoding error darcs-hash:20080116013924-a4fee-802818436b13cc8d3df5d772074a78cc685ccd10 --- Data/Encoding/UTF16.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Data/Encoding/UTF16.hs b/Data/Encoding/UTF16.hs index 38fca04..66e3630 100644 --- a/Data/Encoding/UTF16.hs +++ b/Data/Encoding/UTF16.hs @@ -11,7 +11,7 @@ import Data.Char(ord,chr) import Data.Bits import Data.Int import Data.Word -import Data.ByteString +import Data.ByteString as BS import qualified Data.ByteString.Lazy as LBS import Prelude hiding (length) import Control.Exception @@ -85,7 +85,10 @@ instance Encoding UTF16 where Nothing -> decode' True 0 Just big -> decode' big 2 where - decode' be i = c:decode' be (i+took) + l = BS.length str + decode' be i = if i>=l + then [] + else c:decode' be (i+took) where (c,took) = mapException (\ex -> case ex of ErrorCall _ -> DynException (toDyn UnexpectedEnd) @@ -98,7 +101,10 @@ instance Encoding UTF16 where Nothing -> decode' True 0 Just big -> decode' big 2 where - decode' be i = c:decode' be (i+took) + l = LBS.length str + decode' be i = if i>=l + then [] + else c:decode' be (i+took) where (c,took) = mapException (\ex -> case ex of ErrorCall _ -> DynException (toDyn UnexpectedEnd)