Last active
January 3, 2016 17:38
-
-
Save reinh/8496570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
encode :: [Word8] => BL.ByteString | |
encode = runPut . putZSCII | |
putZSCII :: [Word8] -> Put | |
putZSCII zstring = do | |
mapM_ | |
(putWord16be . encodeZchar) | |
(chunksOf 3 zstring) | |
putWord16be 0xb1000000000000000 | |
encodeZchar :: [Word8] -> Word16 | |
encodeZchar = go . fmap fromIntegral | |
where | |
go [w1, w2, w3] = w1 << 10 .|. w2 << 5 .|. w3 | |
go [w1, w2] = go [w1, w2, 5] | |
go [w1] = go [w1, 5, 5] | |
(<<) = shiftL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment