| 1 |
-- {-# OPTIONS_GHC -funfolding-fun-discount=90 #-} |
| 2 |
-- | |
| 3 |
-- Module : Data.Text.Normalize |
| 4 |
-- Copyright : (c) 2016 Harendra Kumar |
| 5 |
-- |
| 6 |
-- License : BSD-3-Clause |
| 7 |
-- Maintainer : [email protected] |
| 8 |
-- Stability : experimental |
| 9 |
-- Portability : GHC |
| 10 |
-- |
| 11 |
-- Unicode normalization for @Text@ data type. |
| 12 |
-- |
| 13 |
module Data.Text.Normalize |
| 14 |
( |
| 15 |
-- * Normalization Modes |
| 16 |
NormalizationMode(..) |
| 17 |
-- * Normalization API |
| 18 |
, normalize |
| 19 |
) where |
| 20 |
|
| 21 |
import Data.Text (Text) |
| 22 |
import Data.Unicode.Types (NormalizationMode(..)) |
| 23 |
|
| 24 |
-- Internal modules |
| 25 |
import Data.Unicode.Internal.NormalizeStream |
| 26 |
( DecomposeMode(..) |
| 27 |
, stream |
| 28 |
, unstream |
| 29 |
, unstreamC |
| 30 |
) |
| 31 |
|
| 32 |
-- | Perform Unicode normalization on @Text@ according to the specified |
| 33 |
-- normalization mode. |
| 34 |
normalize :: NormalizationMode -> Text -> Text |
| 35 |
normalize mode = |
| 36 |
case mode of |
| 37 |
NFD -> (unstream Canonical) . stream |
| 38 |
NFKD -> (unstream Kompat) . stream |
| 39 |
NFC -> (unstreamC Canonical) . stream |
| 40 |
NFKC -> (unstreamC Kompat) . stream |