| 1 |
-- | |
| 2 |
-- Module : Data.ByteString.UTF8.Normalize |
| 3 |
-- Copyright : (c) 2016 Harendra Kumar |
| 4 |
-- |
| 5 |
-- License : BSD-3-Clause |
| 6 |
-- Maintainer : [email protected] |
| 7 |
-- Stability : experimental |
| 8 |
-- Portability : GHC |
| 9 |
-- |
| 10 |
-- Unicode normalization for @ByteString@ data type. |
| 11 |
-- |
| 12 |
module Data.ByteString.UTF8.Normalize |
| 13 |
{-# DEPRECATED "Convert ByteString to Text and then normalize" #-} |
| 14 |
( |
| 15 |
-- * Normalization Modes |
| 16 |
NormalizationMode(..) |
| 17 |
-- * Normalization API |
| 18 |
, normalize |
| 19 |
) where |
| 20 |
|
| 21 |
import Data.ByteString (ByteString) |
| 22 |
import Data.Text.Encoding (decodeUtf8, encodeUtf8) |
| 23 |
import Data.Unicode.Types (NormalizationMode(..)) |
| 24 |
import qualified Data.Text.Normalize as T |
| 25 |
|
| 26 |
-- This is now simply a wrapper over Text normalization |
| 27 |
|
| 28 |
-- | Perform Unicode normalization on a UTF8 encoded @ByteString@ according to |
| 29 |
-- the specified normalization mode. |
| 30 |
normalize :: NormalizationMode -> ByteString -> ByteString |
| 31 |
normalize mode = (encodeUtf8 . T.normalize mode . decodeUtf8) |