Skip to content
Snippets Groups Projects
Commit c9c30814 authored by glguy's avatar glguy
Browse files

Whitespace and tabs

parent 31969fde
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
-- Module : Codec.Binary.UTF8.String -- Module : Codec.Binary.UTF8.String
-- Copyright : (c) Eric Mertens 2007 -- Copyright : (c) Eric Mertens 2007
-- License : BSD3-style (see LICENSE) -- License : BSD3-style (see LICENSE)
-- --
-- Maintainer: emertens@galois.com -- Maintainer: emertens@galois.com
-- Stability : experimental -- Stability : experimental
-- Portability : portable -- Portability : portable
...@@ -21,7 +21,7 @@ module Codec.Binary.UTF8.String ( ...@@ -21,7 +21,7 @@ module Codec.Binary.UTF8.String (
, encodeString , encodeString
, decodeString , decodeString
, encodeChar , encodeChar
, isUTF8Encoded , isUTF8Encoded
, utf8Encode , utf8Encode
) where ) where
...@@ -122,7 +122,7 @@ utf8Encode str ...@@ -122,7 +122,7 @@ utf8Encode str
-- | @isUTF8Encoded str@ tries to recognize input string as being in UTF-8 form. -- | @isUTF8Encoded str@ tries to recognize input string as being in UTF-8 form.
isUTF8Encoded :: String -> Bool isUTF8Encoded :: String -> Bool
isUTF8Encoded [] = True isUTF8Encoded [] = True
isUTF8Encoded (x:xs) = isUTF8Encoded (x:xs) =
case ox of case ox of
_ | ox < 0x80 -> isUTF8Encoded xs _ | ox < 0x80 -> isUTF8Encoded xs
| ox > 0xff -> False | ox > 0xff -> False
...@@ -135,14 +135,14 @@ isUTF8Encoded (x:xs) = ...@@ -135,14 +135,14 @@ isUTF8Encoded (x:xs) =
| otherwise -> False | otherwise -> False
where where
ox = toW32 x ox = toW32 x
toW32 :: Char -> Word32 toW32 :: Char -> Word32
toW32 ch = fromIntegral (fromEnum ch) toW32 ch = fromIntegral (fromEnum ch)
check1 = check1 =
case xs of case xs of
[] -> False [] -> False
c1 : ds c1 : ds
| oc .&. 0xc0 /= 0x80 || d < 0x000080 -> False | oc .&. 0xc0 /= 0x80 || d < 0x000080 -> False
| otherwise -> isUTF8Encoded ds | otherwise -> isUTF8Encoded ds
where where
...@@ -153,15 +153,15 @@ isUTF8Encoded (x:xs) = ...@@ -153,15 +153,15 @@ isUTF8Encoded (x:xs) =
check_byte i mask overlong = aux i xs (ox .&. mask) check_byte i mask overlong = aux i xs (ox .&. mask)
where where
aux 0 rs acc aux 0 rs acc
| overlong <= acc && | overlong <= acc &&
acc <= 0x10ffff && acc <= 0x10ffff &&
(acc < 0xd800 || 0xdfff < acc) && (acc < 0xd800 || 0xdfff < acc) &&
(acc < 0xfffe || 0xffff < acc) = isUTF8Encoded rs (acc < 0xfffe || 0xffff < acc) = isUTF8Encoded rs
| otherwise = False | otherwise = False
aux n (r:rs) acc aux n (r:rs) acc
| toW32 r .&. 0xc0 == 0x80 = | toW32 r .&. 0xc0 == 0x80 =
aux (n-1) rs (acc `shiftL` 6 .|. (toW32 r .&. 0x3f)) aux (n-1) rs (acc `shiftL` 6 .|. (toW32 r .&. 0x3f))
aux _ _ _ = False aux _ _ _ = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment