File: ASCII.hs

package info (click to toggle)
haskell-encoding 0.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,392 kB
  • sloc: haskell: 4,372; ansic: 11; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 591 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{-# LANGUAGE DeriveDataTypeable #-}
module Data.Encoding.ASCII where

import Control.Throws
import Data.Char
import Data.Encoding.Base
import Data.Encoding.ByteSource
import Data.Encoding.ByteSink
import Data.Encoding.Exception
import Data.Typeable

data ASCII = ASCII deriving (Show,Eq,Typeable)

instance Encoding ASCII where
    decodeChar _ = do
      w <- fetchWord8
      return $ chr $ fromIntegral w
    encodeChar enc c
      | encodeable enc c = pushWord8 . fromIntegral . ord $ c
      | otherwise        = throwException . HasNoRepresentation $ c
    encodeable _ c = c < '\128'