File: Normalize.hs

package info (click to toggle)
haskell-unicode-transforms 0.4.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,312 kB
  • sloc: haskell: 786; sh: 15; makefile: 7
file content (40 lines) | stat: -rw-r--r-- 1,026 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- {-# OPTIONS_GHC -funfolding-fun-discount=90 #-}
-- |
-- Module      : Data.Text.Normalize
-- Copyright   : (c) 2016 Harendra Kumar
--
-- License     : BSD-3-Clause
-- Maintainer  : harendra.kumar@gmail.com
-- Stability   : experimental
-- Portability : GHC
--
-- Unicode normalization for @Text@ data type.
--
module Data.Text.Normalize
    (
    -- * Normalization Modes
      NormalizationMode(..)
    -- * Normalization API
    , normalize
    ) where

import Data.Text (Text)
import Data.Unicode.Types (NormalizationMode(..))

-- Internal modules
import Data.Unicode.Internal.NormalizeStream
    ( DecomposeMode(..)
    , stream
    , unstream
    , unstreamC
    )

-- | Perform Unicode normalization on @Text@ according to the specified
-- normalization mode.
normalize :: NormalizationMode -> Text -> Text
normalize mode =
    case mode of
      NFD  -> (unstream Canonical)   . stream
      NFKD -> (unstream Kompat)  . stream
      NFC  -> (unstreamC Canonical)  . stream
      NFKC -> (unstreamC Kompat) . stream