Fixed UTF16 decoding error
darcs-hash:20080116013924-a4fee-802818436b13cc8d3df5d772074a78cc685ccd10
This commit is contained in:
parent
5a0a697cb8
commit
529953686a
@ -11,7 +11,7 @@ import Data.Char(ord,chr)
|
|||||||
import Data.Bits
|
import Data.Bits
|
||||||
import Data.Int
|
import Data.Int
|
||||||
import Data.Word
|
import Data.Word
|
||||||
import Data.ByteString
|
import Data.ByteString as BS
|
||||||
import qualified Data.ByteString.Lazy as LBS
|
import qualified Data.ByteString.Lazy as LBS
|
||||||
import Prelude hiding (length)
|
import Prelude hiding (length)
|
||||||
import Control.Exception
|
import Control.Exception
|
||||||
@ -85,7 +85,10 @@ instance Encoding UTF16 where
|
|||||||
Nothing -> decode' True 0
|
Nothing -> decode' True 0
|
||||||
Just big -> decode' big 2
|
Just big -> decode' big 2
|
||||||
where
|
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
|
where
|
||||||
(c,took) = mapException (\ex -> case ex of
|
(c,took) = mapException (\ex -> case ex of
|
||||||
ErrorCall _ -> DynException (toDyn UnexpectedEnd)
|
ErrorCall _ -> DynException (toDyn UnexpectedEnd)
|
||||||
@ -98,7 +101,10 @@ instance Encoding UTF16 where
|
|||||||
Nothing -> decode' True 0
|
Nothing -> decode' True 0
|
||||||
Just big -> decode' big 2
|
Just big -> decode' big 2
|
||||||
where
|
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
|
where
|
||||||
(c,took) = mapException (\ex -> case ex of
|
(c,took) = mapException (\ex -> case ex of
|
||||||
ErrorCall _ -> DynException (toDyn UnexpectedEnd)
|
ErrorCall _ -> DynException (toDyn UnexpectedEnd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user