Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 1 #12

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Codec/Archive/Zip/CP437.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ where

import Data.ByteString (ByteString)
import Data.Char
import Data.Monoid
import Data.Text (Text)
import Data.Text.Lazy (toStrict)
import Data.Word (Word8)
import qualified Data.ByteString as B
import qualified Data.Text.Lazy.Builder as LB
import qualified Data.Text as T

-- | Decode a 'ByteString' containing CP 437 encoded text.

decodeCP437 :: ByteString -> Text
decodeCP437 = toStrict . LB.toLazyText . B.foldl' f mempty
where f xs b = xs <> LB.singleton (decodeByteCP437 b)

decodeCP437 bs = T.unfoldrN
(B.length bs)
(fmap (\(b,rest) -> (decodeByteCP437 b, rest)) . B.uncons)
bs


-- | Decode single byte of CP437 encoded text.

decodeByteCP437 :: Word8 -> Char
Expand Down Expand Up @@ -160,4 +161,4 @@ decodeByteCP437 byte = chr $ case byte of
253 -> 178
254 -> 9632
255 -> 160
x -> fromIntegral x -- the rest of characters translate directly
x -> fromIntegral x -- the rest of characters translate directly