Skip to content

Commit

Permalink
Merge 9670f9b into 8ac5c5c
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelt committed Mar 5, 2016
2 parents 8ac5c5c + 9670f9b commit c001564
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 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

0 comments on commit c001564

Please sign in to comment.