File: ISO88591.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 (23 lines) | stat: -rw-r--r-- 748 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
22
23
{-# LANGUAGE DeriveDataTypeable #-}
{- | Implements ISO\/IEC 8859-1 alias latin-1 encoding. See <http://en.wikipedia.org/wiki/ISO/IEC_8859-1> for further information.
 -}
module Data.Encoding.ISO88591 where

import Control.Throws
import Data.Encoding.Base
import Data.Encoding.Exception
import Data.Encoding.ByteSource
import Data.Encoding.ByteSink
import Data.Char (ord,chr)
import Data.Typeable

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

instance Encoding ISO88591 where
    encodeChar _ c
               | c > '\255' = throwException (HasNoRepresentation c)
               | otherwise = pushWord8 (fromIntegral $ ord c)
    decodeChar _ = do
      w <- fetchWord8
      return (chr $ fromIntegral w)
    encodeable _ c = c <= '\255'