File: NoClass.hs

package info (click to toggle)
haskell-case-insensitive 1.2.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: haskell: 223; makefile: 3
file content (24 lines) | stat: -rw-r--r-- 659 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module NoClass ( CI, mk ) where

import           Control.DeepSeq            ( NFData, rnf, deepseq )
import           Data.ByteString            ( ByteString )
import qualified Data.ByteString      as B  ( map )
import           Data.Word                  ( Word8 )

data CI s = CI !s !s

instance NFData s => NFData (CI s) where
    rnf (CI o f) = o `deepseq` f `deepseq` ()

mk :: ByteString -> CI ByteString
mk s = CI s (foldCase s)

foldCase :: ByteString -> ByteString
foldCase = B.map toLower8

toLower8 :: Word8 -> Word8
toLower8 w
  |  65 <= w && w <=  90 ||
    192 <= w && w <= 214 ||
    216 <= w && w <= 222 = w + 32
  | otherwise            = w