{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}

-- | Core types for Internationalized Domain Names (IDN) processing.
--
-- This module provides types for domain name processing following the IDNA2008
-- specification (RFC 5890-5893). Types are organized into logical groups:
-- errors, domain structures, Unicode properties, and Punycode internals.
--
-- == Example
--
-- >>> mkLabel "example"
-- Right (ULabel "example")
--
-- >>> mkDomainName "example.com"
-- Right (DomainName {labels = ...})
module Data.Text.IDN.Types
  ( -- * Error Types
    IDNError(..)
  , HyphenError(..)
  , PunycodeError(..)
  
    -- * Domain Types
  , Label(..)
  , DomainName(..)
  , mkLabel
  , mkDomainName
  
    -- * Unicode Property Types
  , CodePointStatus(..)
  , BidiClass(..)
  , ContextRule(..)
  , BidiRule(..)
  , Script(..)
  
    -- * Punycode Types
  , PunycodeState(..)
  , PunycodeParams(..)
  , initialState
  , punycodeParams
  ) where

import Data.Text (Text)
import qualified Data.Text as T
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import GHC.Generics (Generic)
import Control.DeepSeq (NFData)

-- | IDN processing errors with detailed context.
--
-- Errors include validation failures, encoding issues, and constraint violations
-- per IDNA2008 (RFC 5890-5893).
data IDNError
  = EmptyLabel
    -- ^ Domain label cannot be empty
  | LabelTooLong 
      { IDNError -> Int
actualLength :: Int
        -- ^ Actual label length
      , IDNError -> Int
maxLength :: Int
        -- ^ Maximum allowed length (63)
      }
    -- ^ Domain label exceeds maximum length
  | TotalDomainTooLong
      { actualLength :: Int
        -- ^ Actual domain length
      , maxLength :: Int
        -- ^ Maximum allowed length (253)
      }
    -- ^ Complete domain name exceeds maximum length
  | InvalidHyphenPosition HyphenError
    -- ^ Hyphen appears in invalid position
  | StartsWithCombiningMark
      { IDNError -> Char
character :: Char
        -- ^ The combining mark character
      , IDNError -> Int
codepoint :: Int
        -- ^ Unicode code point value
      }
    -- ^ Label starts with a combining mark (invalid)
  | DisallowedCodePoint
      { character :: Char
        -- ^ The disallowed character
      , codepoint :: Int
        -- ^ Unicode code point value
      }
    -- ^ Code point is not allowed in IDN labels
  | InvalidContext
      { character :: Char
        -- ^ The character that failed context validation
      , IDNError -> ContextRule
contextRule :: ContextRule
        -- ^ The specific context rule violated
      , IDNError -> Int
position :: Int
        -- ^ Position in label where error occurred
      , IDNError -> Text
context :: Text
        -- ^ The full label context
      }
    -- ^ Contextual rule violation (CONTEXTJ/CONTEXTO)
  | BidiViolation
      { IDNError -> BidiRule
bidiRule :: BidiRule
        -- ^ The bidirectional rule violated
      , IDNError -> Text
label :: Text
        -- ^ The label that failed validation
      }
    -- ^ Bidirectional text rule violation (RFC 5893)
  | PunycodeDecodeError
      { IDNError -> Text
input :: Text
        -- ^ The input that failed to decode
      , IDNError -> Text
reason :: Text
        -- ^ Reason for decode failure
      }
    -- ^ Error during Punycode decoding
  deriving (Int -> IDNError -> ShowS
[IDNError] -> ShowS
IDNError -> String
(Int -> IDNError -> ShowS)
-> (IDNError -> String) -> ([IDNError] -> ShowS) -> Show IDNError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> IDNError -> ShowS
showsPrec :: Int -> IDNError -> ShowS
$cshow :: IDNError -> String
show :: IDNError -> String
$cshowList :: [IDNError] -> ShowS
showList :: [IDNError] -> ShowS
Show, IDNError -> IDNError -> Bool
(IDNError -> IDNError -> Bool)
-> (IDNError -> IDNError -> Bool) -> Eq IDNError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: IDNError -> IDNError -> Bool
== :: IDNError -> IDNError -> Bool
$c/= :: IDNError -> IDNError -> Bool
/= :: IDNError -> IDNError -> Bool
Eq, (forall x. IDNError -> Rep IDNError x)
-> (forall x. Rep IDNError x -> IDNError) -> Generic IDNError
forall x. Rep IDNError x -> IDNError
forall x. IDNError -> Rep IDNError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. IDNError -> Rep IDNError x
from :: forall x. IDNError -> Rep IDNError x
$cto :: forall x. Rep IDNError x -> IDNError
to :: forall x. Rep IDNError x -> IDNError
Generic)

instance NFData IDNError

-- | Hyphen position errors.
--
-- Domain labels cannot start or end with hyphens, and hyphens at positions
-- 3-4 are reserved for Punycode encoding.
data HyphenError
  = StartsWithHyphen
    -- ^ Label starts with hyphen (invalid)
  | EndsWithHyphen
    -- ^ Label ends with hyphen (invalid)
  | HyphensAt3And4NotPunycode
    -- ^ Hyphens at positions 3-4 but not a valid Punycode label
  deriving (Int -> HyphenError -> ShowS
[HyphenError] -> ShowS
HyphenError -> String
(Int -> HyphenError -> ShowS)
-> (HyphenError -> String)
-> ([HyphenError] -> ShowS)
-> Show HyphenError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HyphenError -> ShowS
showsPrec :: Int -> HyphenError -> ShowS
$cshow :: HyphenError -> String
show :: HyphenError -> String
$cshowList :: [HyphenError] -> ShowS
showList :: [HyphenError] -> ShowS
Show, HyphenError -> HyphenError -> Bool
(HyphenError -> HyphenError -> Bool)
-> (HyphenError -> HyphenError -> Bool) -> Eq HyphenError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HyphenError -> HyphenError -> Bool
== :: HyphenError -> HyphenError -> Bool
$c/= :: HyphenError -> HyphenError -> Bool
/= :: HyphenError -> HyphenError -> Bool
Eq, (forall x. HyphenError -> Rep HyphenError x)
-> (forall x. Rep HyphenError x -> HyphenError)
-> Generic HyphenError
forall x. Rep HyphenError x -> HyphenError
forall x. HyphenError -> Rep HyphenError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HyphenError -> Rep HyphenError x
from :: forall x. HyphenError -> Rep HyphenError x
$cto :: forall x. Rep HyphenError x -> HyphenError
to :: forall x. Rep HyphenError x -> HyphenError
Generic)

instance NFData HyphenError

-- | Punycode encoding/decoding errors.
--
-- These errors occur during low-level Punycode operations. For domain-level
-- errors, see 'IDNError'.
data PunycodeError
  = InvalidPunycode Text
    -- ^ Malformed Punycode string with reason
  | Overflow
    -- ^ Integer overflow during encoding/decoding
  deriving (Int -> PunycodeError -> ShowS
[PunycodeError] -> ShowS
PunycodeError -> String
(Int -> PunycodeError -> ShowS)
-> (PunycodeError -> String)
-> ([PunycodeError] -> ShowS)
-> Show PunycodeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PunycodeError -> ShowS
showsPrec :: Int -> PunycodeError -> ShowS
$cshow :: PunycodeError -> String
show :: PunycodeError -> String
$cshowList :: [PunycodeError] -> ShowS
showList :: [PunycodeError] -> ShowS
Show, PunycodeError -> PunycodeError -> Bool
(PunycodeError -> PunycodeError -> Bool)
-> (PunycodeError -> PunycodeError -> Bool) -> Eq PunycodeError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PunycodeError -> PunycodeError -> Bool
== :: PunycodeError -> PunycodeError -> Bool
$c/= :: PunycodeError -> PunycodeError -> Bool
/= :: PunycodeError -> PunycodeError -> Bool
Eq, (forall x. PunycodeError -> Rep PunycodeError x)
-> (forall x. Rep PunycodeError x -> PunycodeError)
-> Generic PunycodeError
forall x. Rep PunycodeError x -> PunycodeError
forall x. PunycodeError -> Rep PunycodeError x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PunycodeError -> Rep PunycodeError x
from :: forall x. PunycodeError -> Rep PunycodeError x
$cto :: forall x. Rep PunycodeError x -> PunycodeError
to :: forall x. Rep PunycodeError x -> PunycodeError
Generic)

instance NFData PunycodeError

-- | Domain label in either Unicode or ASCII/Punycode form.
--
-- Labels are the components of a domain name separated by dots. They can be
-- in Unicode form (U-label) or ASCII/Punycode form (A-label).
data Label
  = ULabel Text
    -- ^ Unicode label (U-label) - contains Unicode characters
  | ALabel Text
    -- ^ ASCII/Punycode label (A-label) - contains ASCII or Punycode with xn-- prefix
  deriving (Int -> Label -> ShowS
[Label] -> ShowS
Label -> String
(Int -> Label -> ShowS)
-> (Label -> String) -> ([Label] -> ShowS) -> Show Label
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Label -> ShowS
showsPrec :: Int -> Label -> ShowS
$cshow :: Label -> String
show :: Label -> String
$cshowList :: [Label] -> ShowS
showList :: [Label] -> ShowS
Show, Label -> Label -> Bool
(Label -> Label -> Bool) -> (Label -> Label -> Bool) -> Eq Label
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Label -> Label -> Bool
== :: Label -> Label -> Bool
$c/= :: Label -> Label -> Bool
/= :: Label -> Label -> Bool
Eq, (forall x. Label -> Rep Label x)
-> (forall x. Rep Label x -> Label) -> Generic Label
forall x. Rep Label x -> Label
forall x. Label -> Rep Label x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Label -> Rep Label x
from :: forall x. Label -> Rep Label x
$cto :: forall x. Rep Label x -> Label
to :: forall x. Rep Label x -> Label
Generic)

instance NFData Label

-- | Complete domain name consisting of one or more labels.
--
-- A domain name is a non-empty sequence of labels separated by dots.
-- The total length must not exceed 253 characters.
newtype DomainName = DomainName 
  { DomainName -> NonEmpty Label
labels :: NonEmpty Label
    -- ^ Non-empty list of domain labels
  }
  deriving (Int -> DomainName -> ShowS
[DomainName] -> ShowS
DomainName -> String
(Int -> DomainName -> ShowS)
-> (DomainName -> String)
-> ([DomainName] -> ShowS)
-> Show DomainName
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DomainName -> ShowS
showsPrec :: Int -> DomainName -> ShowS
$cshow :: DomainName -> String
show :: DomainName -> String
$cshowList :: [DomainName] -> ShowS
showList :: [DomainName] -> ShowS
Show, DomainName -> DomainName -> Bool
(DomainName -> DomainName -> Bool)
-> (DomainName -> DomainName -> Bool) -> Eq DomainName
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DomainName -> DomainName -> Bool
== :: DomainName -> DomainName -> Bool
$c/= :: DomainName -> DomainName -> Bool
/= :: DomainName -> DomainName -> Bool
Eq, (forall x. DomainName -> Rep DomainName x)
-> (forall x. Rep DomainName x -> DomainName) -> Generic DomainName
forall x. Rep DomainName x -> DomainName
forall x. DomainName -> Rep DomainName x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DomainName -> Rep DomainName x
from :: forall x. DomainName -> Rep DomainName x
$cto :: forall x. Rep DomainName x -> DomainName
to :: forall x. Rep DomainName x -> DomainName
Generic)

instance NFData DomainName

-- | Smart constructor for 'Label' with invariant enforcement.
--
-- Validates that the label is non-empty and within length constraints.
-- Automatically detects A-labels (those starting with "xn--").
--
-- === Examples
--
-- >>> mkLabel "example"
-- Right (ULabel "example")
--
-- >>> mkLabel "xn--mnchen-3ya"
-- Right (ALabel "xn--mnchen-3ya")
--
-- >>> mkLabel ""
-- Left EmptyLabel
mkLabel :: Text -> Either IDNError Label
mkLabel :: Text -> Either IDNError Label
mkLabel Text
text
  | Text -> Bool
T.null Text
text = IDNError -> Either IDNError Label
forall a b. a -> Either a b
Left IDNError
EmptyLabel
  | Text -> Int
T.length Text
text Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
63 = IDNError -> Either IDNError Label
forall a b. a -> Either a b
Left (Int -> Int -> IDNError
LabelTooLong (Text -> Int
T.length Text
text) Int
63)
  | Bool
otherwise =
      -- RFC 5891/3490: Domain labels are case-insensitive, normalize to lowercase
      let normalized :: Text
normalized = Text -> Text
T.toLower Text
text
      -- RFC 5891 Section 5.1: A-labels start with "xn--"
      in if Text
"xn--" Text -> Text -> Bool
`T.isPrefixOf` Text
normalized
           then Label -> Either IDNError Label
forall a b. b -> Either a b
Right (Text -> Label
ALabel Text
normalized)
           else Label -> Either IDNError Label
forall a b. b -> Either a b
Right (Text -> Label
ULabel Text
normalized)

-- | Smart constructor for 'DomainName' with invariant enforcement.
--
-- Validates that the domain is non-empty, within length constraints, and
-- properly formatted. Splits on dots to create individual labels.
--
-- === Examples
--
-- >>> mkDomainName "example.com"
-- Right (DomainName {labels = ...})
--
-- >>> mkDomainName ""
-- Left EmptyLabel
mkDomainName :: Text -> Either IDNError DomainName
mkDomainName :: Text -> Either IDNError DomainName
mkDomainName Text
text = do
  if Text -> Bool
T.null Text
text
    then IDNError -> Either IDNError DomainName
forall a b. a -> Either a b
Left IDNError
EmptyLabel
    else if Text -> Int
T.length Text
text Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
253
      then IDNError -> Either IDNError DomainName
forall a b. a -> Either a b
Left (Int -> Int -> IDNError
TotalDomainTooLong (Text -> Int
T.length Text
text) Int
253)
      else do
        -- RFC 3490 Section 3.1: Normalize alternative dot separators
        -- U+3002 IDEOGRAPHIC FULL STOP, U+FF0E FULLWIDTH FULL STOP, U+FF61 HALFWIDTH IDEOGRAPHIC FULL STOP
        let normalized :: Text
normalized = (Char -> Char) -> Text -> Text
T.map Char -> Char
normalizeDot Text
text
            labelTexts :: [Text]
labelTexts = HasCallStack => Text -> Text -> [Text]
Text -> Text -> [Text]
T.splitOn Text
"." Text
normalized
        [Label]
labelList <- (Text -> Either IDNError Label)
-> [Text] -> Either IDNError [Label]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse Text -> Either IDNError Label
mkLabel [Text]
labelTexts
        case [Label] -> Maybe (NonEmpty Label)
forall a. [a] -> Maybe (NonEmpty a)
NE.nonEmpty [Label]
labelList of
          Maybe (NonEmpty Label)
Nothing -> IDNError -> Either IDNError DomainName
forall a b. a -> Either a b
Left IDNError
EmptyLabel
          Just NonEmpty Label
ne -> DomainName -> Either IDNError DomainName
forall a b. b -> Either a b
Right (NonEmpty Label -> DomainName
DomainName NonEmpty Label
ne)
  where
    normalizeDot :: Char -> Char
normalizeDot Char
'\x3002' = Char
'.'  -- IDEOGRAPHIC FULL STOP
    normalizeDot Char
'\xFF0E' = Char
'.'  -- FULLWIDTH FULL STOP
    normalizeDot Char
'\xFF61' = Char
'.'  -- HALFWIDTH IDEOGRAPHIC FULL STOP
    normalizeDot Char
c = Char
c

-- | IDNA2008 code point status per RFC 5892.
--
-- Each Unicode code point is classified according to its validity for use
-- in IDN labels.
data CodePointStatus
  = PVALID
    -- ^ Always valid in domain names
  | DISALLOWED
    -- ^ Never valid in domain names
  | CONTEXTJ
    -- ^ Valid only in specific contexts (Join_Control)
  | CONTEXTO
    -- ^ Valid only in specific contexts (Other)
  | UNASSIGNED
    -- ^ Not assigned in this Unicode version
  deriving (Int -> CodePointStatus -> ShowS
[CodePointStatus] -> ShowS
CodePointStatus -> String
(Int -> CodePointStatus -> ShowS)
-> (CodePointStatus -> String)
-> ([CodePointStatus] -> ShowS)
-> Show CodePointStatus
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CodePointStatus -> ShowS
showsPrec :: Int -> CodePointStatus -> ShowS
$cshow :: CodePointStatus -> String
show :: CodePointStatus -> String
$cshowList :: [CodePointStatus] -> ShowS
showList :: [CodePointStatus] -> ShowS
Show, CodePointStatus -> CodePointStatus -> Bool
(CodePointStatus -> CodePointStatus -> Bool)
-> (CodePointStatus -> CodePointStatus -> Bool)
-> Eq CodePointStatus
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CodePointStatus -> CodePointStatus -> Bool
== :: CodePointStatus -> CodePointStatus -> Bool
$c/= :: CodePointStatus -> CodePointStatus -> Bool
/= :: CodePointStatus -> CodePointStatus -> Bool
Eq, Eq CodePointStatus
Eq CodePointStatus =>
(CodePointStatus -> CodePointStatus -> Ordering)
-> (CodePointStatus -> CodePointStatus -> Bool)
-> (CodePointStatus -> CodePointStatus -> Bool)
-> (CodePointStatus -> CodePointStatus -> Bool)
-> (CodePointStatus -> CodePointStatus -> Bool)
-> (CodePointStatus -> CodePointStatus -> CodePointStatus)
-> (CodePointStatus -> CodePointStatus -> CodePointStatus)
-> Ord CodePointStatus
CodePointStatus -> CodePointStatus -> Bool
CodePointStatus -> CodePointStatus -> Ordering
CodePointStatus -> CodePointStatus -> CodePointStatus
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: CodePointStatus -> CodePointStatus -> Ordering
compare :: CodePointStatus -> CodePointStatus -> Ordering
$c< :: CodePointStatus -> CodePointStatus -> Bool
< :: CodePointStatus -> CodePointStatus -> Bool
$c<= :: CodePointStatus -> CodePointStatus -> Bool
<= :: CodePointStatus -> CodePointStatus -> Bool
$c> :: CodePointStatus -> CodePointStatus -> Bool
> :: CodePointStatus -> CodePointStatus -> Bool
$c>= :: CodePointStatus -> CodePointStatus -> Bool
>= :: CodePointStatus -> CodePointStatus -> Bool
$cmax :: CodePointStatus -> CodePointStatus -> CodePointStatus
max :: CodePointStatus -> CodePointStatus -> CodePointStatus
$cmin :: CodePointStatus -> CodePointStatus -> CodePointStatus
min :: CodePointStatus -> CodePointStatus -> CodePointStatus
Ord, Int -> CodePointStatus
CodePointStatus -> Int
CodePointStatus -> [CodePointStatus]
CodePointStatus -> CodePointStatus
CodePointStatus -> CodePointStatus -> [CodePointStatus]
CodePointStatus
-> CodePointStatus -> CodePointStatus -> [CodePointStatus]
(CodePointStatus -> CodePointStatus)
-> (CodePointStatus -> CodePointStatus)
-> (Int -> CodePointStatus)
-> (CodePointStatus -> Int)
-> (CodePointStatus -> [CodePointStatus])
-> (CodePointStatus -> CodePointStatus -> [CodePointStatus])
-> (CodePointStatus -> CodePointStatus -> [CodePointStatus])
-> (CodePointStatus
    -> CodePointStatus -> CodePointStatus -> [CodePointStatus])
-> Enum CodePointStatus
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: CodePointStatus -> CodePointStatus
succ :: CodePointStatus -> CodePointStatus
$cpred :: CodePointStatus -> CodePointStatus
pred :: CodePointStatus -> CodePointStatus
$ctoEnum :: Int -> CodePointStatus
toEnum :: Int -> CodePointStatus
$cfromEnum :: CodePointStatus -> Int
fromEnum :: CodePointStatus -> Int
$cenumFrom :: CodePointStatus -> [CodePointStatus]
enumFrom :: CodePointStatus -> [CodePointStatus]
$cenumFromThen :: CodePointStatus -> CodePointStatus -> [CodePointStatus]
enumFromThen :: CodePointStatus -> CodePointStatus -> [CodePointStatus]
$cenumFromTo :: CodePointStatus -> CodePointStatus -> [CodePointStatus]
enumFromTo :: CodePointStatus -> CodePointStatus -> [CodePointStatus]
$cenumFromThenTo :: CodePointStatus
-> CodePointStatus -> CodePointStatus -> [CodePointStatus]
enumFromThenTo :: CodePointStatus
-> CodePointStatus -> CodePointStatus -> [CodePointStatus]
Enum, CodePointStatus
CodePointStatus -> CodePointStatus -> Bounded CodePointStatus
forall a. a -> a -> Bounded a
$cminBound :: CodePointStatus
minBound :: CodePointStatus
$cmaxBound :: CodePointStatus
maxBound :: CodePointStatus
Bounded, (forall x. CodePointStatus -> Rep CodePointStatus x)
-> (forall x. Rep CodePointStatus x -> CodePointStatus)
-> Generic CodePointStatus
forall x. Rep CodePointStatus x -> CodePointStatus
forall x. CodePointStatus -> Rep CodePointStatus x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. CodePointStatus -> Rep CodePointStatus x
from :: forall x. CodePointStatus -> Rep CodePointStatus x
$cto :: forall x. Rep CodePointStatus x -> CodePointStatus
to :: forall x. Rep CodePointStatus x -> CodePointStatus
Generic)

instance NFData CodePointStatus

-- | Unicode bidirectional character class per Unicode Character Database (UCD).
--
-- Used for bidirectional text validation per RFC 5893.
data BidiClass
  = L    -- ^ Left-to-Right
  | R    -- ^ Right-to-Left
  | AL   -- ^ Right-to-Left Arabic
  | AN   -- ^ Arabic Number
  | EN   -- ^ European Number
  | ES   -- ^ European Number Separator
  | ET   -- ^ European Number Terminator
  | CS   -- ^ Common Number Separator
  | NSM  -- ^ Nonspacing Mark
  | BN   -- ^ Boundary Neutral
  | B    -- ^ Paragraph Separator
  | S    -- ^ Segment Separator
  | WS   -- ^ Whitespace
  | ON   -- ^ Other Neutral
  | LRE  -- ^ Left-to-Right Embedding
  | LRO  -- ^ Left-to-Right Override
  | RLE  -- ^ Right-to-Left Embedding
  | RLO  -- ^ Right-to-Left Override
  | PDF  -- ^ Pop Directional Format
  | LRI  -- ^ Left-to-Right Isolate
  | RLI  -- ^ Right-to-Left Isolate
  | FSI  -- ^ First Strong Isolate
  | PDI  -- ^ Pop Directional Isolate
  deriving (Int -> BidiClass -> ShowS
[BidiClass] -> ShowS
BidiClass -> String
(Int -> BidiClass -> ShowS)
-> (BidiClass -> String)
-> ([BidiClass] -> ShowS)
-> Show BidiClass
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BidiClass -> ShowS
showsPrec :: Int -> BidiClass -> ShowS
$cshow :: BidiClass -> String
show :: BidiClass -> String
$cshowList :: [BidiClass] -> ShowS
showList :: [BidiClass] -> ShowS
Show, BidiClass -> BidiClass -> Bool
(BidiClass -> BidiClass -> Bool)
-> (BidiClass -> BidiClass -> Bool) -> Eq BidiClass
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BidiClass -> BidiClass -> Bool
== :: BidiClass -> BidiClass -> Bool
$c/= :: BidiClass -> BidiClass -> Bool
/= :: BidiClass -> BidiClass -> Bool
Eq, Eq BidiClass
Eq BidiClass =>
(BidiClass -> BidiClass -> Ordering)
-> (BidiClass -> BidiClass -> Bool)
-> (BidiClass -> BidiClass -> Bool)
-> (BidiClass -> BidiClass -> Bool)
-> (BidiClass -> BidiClass -> Bool)
-> (BidiClass -> BidiClass -> BidiClass)
-> (BidiClass -> BidiClass -> BidiClass)
-> Ord BidiClass
BidiClass -> BidiClass -> Bool
BidiClass -> BidiClass -> Ordering
BidiClass -> BidiClass -> BidiClass
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BidiClass -> BidiClass -> Ordering
compare :: BidiClass -> BidiClass -> Ordering
$c< :: BidiClass -> BidiClass -> Bool
< :: BidiClass -> BidiClass -> Bool
$c<= :: BidiClass -> BidiClass -> Bool
<= :: BidiClass -> BidiClass -> Bool
$c> :: BidiClass -> BidiClass -> Bool
> :: BidiClass -> BidiClass -> Bool
$c>= :: BidiClass -> BidiClass -> Bool
>= :: BidiClass -> BidiClass -> Bool
$cmax :: BidiClass -> BidiClass -> BidiClass
max :: BidiClass -> BidiClass -> BidiClass
$cmin :: BidiClass -> BidiClass -> BidiClass
min :: BidiClass -> BidiClass -> BidiClass
Ord, Int -> BidiClass
BidiClass -> Int
BidiClass -> [BidiClass]
BidiClass -> BidiClass
BidiClass -> BidiClass -> [BidiClass]
BidiClass -> BidiClass -> BidiClass -> [BidiClass]
(BidiClass -> BidiClass)
-> (BidiClass -> BidiClass)
-> (Int -> BidiClass)
-> (BidiClass -> Int)
-> (BidiClass -> [BidiClass])
-> (BidiClass -> BidiClass -> [BidiClass])
-> (BidiClass -> BidiClass -> [BidiClass])
-> (BidiClass -> BidiClass -> BidiClass -> [BidiClass])
-> Enum BidiClass
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BidiClass -> BidiClass
succ :: BidiClass -> BidiClass
$cpred :: BidiClass -> BidiClass
pred :: BidiClass -> BidiClass
$ctoEnum :: Int -> BidiClass
toEnum :: Int -> BidiClass
$cfromEnum :: BidiClass -> Int
fromEnum :: BidiClass -> Int
$cenumFrom :: BidiClass -> [BidiClass]
enumFrom :: BidiClass -> [BidiClass]
$cenumFromThen :: BidiClass -> BidiClass -> [BidiClass]
enumFromThen :: BidiClass -> BidiClass -> [BidiClass]
$cenumFromTo :: BidiClass -> BidiClass -> [BidiClass]
enumFromTo :: BidiClass -> BidiClass -> [BidiClass]
$cenumFromThenTo :: BidiClass -> BidiClass -> BidiClass -> [BidiClass]
enumFromThenTo :: BidiClass -> BidiClass -> BidiClass -> [BidiClass]
Enum, BidiClass
BidiClass -> BidiClass -> Bounded BidiClass
forall a. a -> a -> Bounded a
$cminBound :: BidiClass
minBound :: BidiClass
$cmaxBound :: BidiClass
maxBound :: BidiClass
Bounded, (forall x. BidiClass -> Rep BidiClass x)
-> (forall x. Rep BidiClass x -> BidiClass) -> Generic BidiClass
forall x. Rep BidiClass x -> BidiClass
forall x. BidiClass -> Rep BidiClass x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BidiClass -> Rep BidiClass x
from :: forall x. BidiClass -> Rep BidiClass x
$cto :: forall x. Rep BidiClass x -> BidiClass
to :: forall x. Rep BidiClass x -> BidiClass
Generic)

instance NFData BidiClass

-- | Contextual validation rules from RFC 5892 Appendix A.
--
-- Some code points are only valid in specific contexts. These rules define
-- those contexts.
data ContextRule
  = ZWNJRule
    -- ^ A.1: Zero Width Non-Joiner (U+200C)
  | ZWJRule
    -- ^ A.2: Zero Width Joiner (U+200D)
  | MiddleDotRule
    -- ^ A.3: Middle Dot (U+00B7)
  | GreekKeraiaRule
    -- ^ A.4: Greek Lower Numeral Sign (U+0375)
  | HebrewGereshRule
    -- ^ A.5: Hebrew Punctuation Geresh (U+05F3)
  | HebrewGershayimRule
    -- ^ A.6: Hebrew Punctuation Gershayim (U+05F4)
  | KatakanaMiddleDotRule
    -- ^ A.7: Katakana Middle Dot (U+30FB)
  | ArabicIndicDigitsRule
    -- ^ A.8: Arabic-Indic Digits (U+0660..U+0669)
  | ExtendedArabicIndicDigitsRule
    -- ^ A.9: Extended Arabic-Indic Digits (U+06F0..U+06F9)
  deriving (Int -> ContextRule -> ShowS
[ContextRule] -> ShowS
ContextRule -> String
(Int -> ContextRule -> ShowS)
-> (ContextRule -> String)
-> ([ContextRule] -> ShowS)
-> Show ContextRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ContextRule -> ShowS
showsPrec :: Int -> ContextRule -> ShowS
$cshow :: ContextRule -> String
show :: ContextRule -> String
$cshowList :: [ContextRule] -> ShowS
showList :: [ContextRule] -> ShowS
Show, ContextRule -> ContextRule -> Bool
(ContextRule -> ContextRule -> Bool)
-> (ContextRule -> ContextRule -> Bool) -> Eq ContextRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ContextRule -> ContextRule -> Bool
== :: ContextRule -> ContextRule -> Bool
$c/= :: ContextRule -> ContextRule -> Bool
/= :: ContextRule -> ContextRule -> Bool
Eq, Eq ContextRule
Eq ContextRule =>
(ContextRule -> ContextRule -> Ordering)
-> (ContextRule -> ContextRule -> Bool)
-> (ContextRule -> ContextRule -> Bool)
-> (ContextRule -> ContextRule -> Bool)
-> (ContextRule -> ContextRule -> Bool)
-> (ContextRule -> ContextRule -> ContextRule)
-> (ContextRule -> ContextRule -> ContextRule)
-> Ord ContextRule
ContextRule -> ContextRule -> Bool
ContextRule -> ContextRule -> Ordering
ContextRule -> ContextRule -> ContextRule
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: ContextRule -> ContextRule -> Ordering
compare :: ContextRule -> ContextRule -> Ordering
$c< :: ContextRule -> ContextRule -> Bool
< :: ContextRule -> ContextRule -> Bool
$c<= :: ContextRule -> ContextRule -> Bool
<= :: ContextRule -> ContextRule -> Bool
$c> :: ContextRule -> ContextRule -> Bool
> :: ContextRule -> ContextRule -> Bool
$c>= :: ContextRule -> ContextRule -> Bool
>= :: ContextRule -> ContextRule -> Bool
$cmax :: ContextRule -> ContextRule -> ContextRule
max :: ContextRule -> ContextRule -> ContextRule
$cmin :: ContextRule -> ContextRule -> ContextRule
min :: ContextRule -> ContextRule -> ContextRule
Ord, Int -> ContextRule
ContextRule -> Int
ContextRule -> [ContextRule]
ContextRule -> ContextRule
ContextRule -> ContextRule -> [ContextRule]
ContextRule -> ContextRule -> ContextRule -> [ContextRule]
(ContextRule -> ContextRule)
-> (ContextRule -> ContextRule)
-> (Int -> ContextRule)
-> (ContextRule -> Int)
-> (ContextRule -> [ContextRule])
-> (ContextRule -> ContextRule -> [ContextRule])
-> (ContextRule -> ContextRule -> [ContextRule])
-> (ContextRule -> ContextRule -> ContextRule -> [ContextRule])
-> Enum ContextRule
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: ContextRule -> ContextRule
succ :: ContextRule -> ContextRule
$cpred :: ContextRule -> ContextRule
pred :: ContextRule -> ContextRule
$ctoEnum :: Int -> ContextRule
toEnum :: Int -> ContextRule
$cfromEnum :: ContextRule -> Int
fromEnum :: ContextRule -> Int
$cenumFrom :: ContextRule -> [ContextRule]
enumFrom :: ContextRule -> [ContextRule]
$cenumFromThen :: ContextRule -> ContextRule -> [ContextRule]
enumFromThen :: ContextRule -> ContextRule -> [ContextRule]
$cenumFromTo :: ContextRule -> ContextRule -> [ContextRule]
enumFromTo :: ContextRule -> ContextRule -> [ContextRule]
$cenumFromThenTo :: ContextRule -> ContextRule -> ContextRule -> [ContextRule]
enumFromThenTo :: ContextRule -> ContextRule -> ContextRule -> [ContextRule]
Enum, ContextRule
ContextRule -> ContextRule -> Bounded ContextRule
forall a. a -> a -> Bounded a
$cminBound :: ContextRule
minBound :: ContextRule
$cmaxBound :: ContextRule
maxBound :: ContextRule
Bounded, (forall x. ContextRule -> Rep ContextRule x)
-> (forall x. Rep ContextRule x -> ContextRule)
-> Generic ContextRule
forall x. Rep ContextRule x -> ContextRule
forall x. ContextRule -> Rep ContextRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ContextRule -> Rep ContextRule x
from :: forall x. ContextRule -> Rep ContextRule x
$cto :: forall x. Rep ContextRule x -> ContextRule
to :: forall x. Rep ContextRule x -> ContextRule
Generic)

instance NFData ContextRule

-- | Bidirectional text rules from RFC 5893.
--
-- These rules ensure proper bidirectional text handling in RTL labels.
data BidiRule
  = Rule1
    -- ^ Presence of RTL characters triggers RTL validation
  | Rule2
    -- ^ First character must be R or AL
  | Rule3
    -- ^ Last character must be R, AL, AN, or EN
  | Rule4
    -- ^ NSM may only follow allowed character types
  | Rule5
    -- ^ ES and CS constraints in RTL labels
  | Rule6
    -- ^ EN and AN cannot be mixed
  deriving (Int -> BidiRule -> ShowS
[BidiRule] -> ShowS
BidiRule -> String
(Int -> BidiRule -> ShowS)
-> (BidiRule -> String) -> ([BidiRule] -> ShowS) -> Show BidiRule
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BidiRule -> ShowS
showsPrec :: Int -> BidiRule -> ShowS
$cshow :: BidiRule -> String
show :: BidiRule -> String
$cshowList :: [BidiRule] -> ShowS
showList :: [BidiRule] -> ShowS
Show, BidiRule -> BidiRule -> Bool
(BidiRule -> BidiRule -> Bool)
-> (BidiRule -> BidiRule -> Bool) -> Eq BidiRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BidiRule -> BidiRule -> Bool
== :: BidiRule -> BidiRule -> Bool
$c/= :: BidiRule -> BidiRule -> Bool
/= :: BidiRule -> BidiRule -> Bool
Eq, Eq BidiRule
Eq BidiRule =>
(BidiRule -> BidiRule -> Ordering)
-> (BidiRule -> BidiRule -> Bool)
-> (BidiRule -> BidiRule -> Bool)
-> (BidiRule -> BidiRule -> Bool)
-> (BidiRule -> BidiRule -> Bool)
-> (BidiRule -> BidiRule -> BidiRule)
-> (BidiRule -> BidiRule -> BidiRule)
-> Ord BidiRule
BidiRule -> BidiRule -> Bool
BidiRule -> BidiRule -> Ordering
BidiRule -> BidiRule -> BidiRule
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BidiRule -> BidiRule -> Ordering
compare :: BidiRule -> BidiRule -> Ordering
$c< :: BidiRule -> BidiRule -> Bool
< :: BidiRule -> BidiRule -> Bool
$c<= :: BidiRule -> BidiRule -> Bool
<= :: BidiRule -> BidiRule -> Bool
$c> :: BidiRule -> BidiRule -> Bool
> :: BidiRule -> BidiRule -> Bool
$c>= :: BidiRule -> BidiRule -> Bool
>= :: BidiRule -> BidiRule -> Bool
$cmax :: BidiRule -> BidiRule -> BidiRule
max :: BidiRule -> BidiRule -> BidiRule
$cmin :: BidiRule -> BidiRule -> BidiRule
min :: BidiRule -> BidiRule -> BidiRule
Ord, Int -> BidiRule
BidiRule -> Int
BidiRule -> [BidiRule]
BidiRule -> BidiRule
BidiRule -> BidiRule -> [BidiRule]
BidiRule -> BidiRule -> BidiRule -> [BidiRule]
(BidiRule -> BidiRule)
-> (BidiRule -> BidiRule)
-> (Int -> BidiRule)
-> (BidiRule -> Int)
-> (BidiRule -> [BidiRule])
-> (BidiRule -> BidiRule -> [BidiRule])
-> (BidiRule -> BidiRule -> [BidiRule])
-> (BidiRule -> BidiRule -> BidiRule -> [BidiRule])
-> Enum BidiRule
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BidiRule -> BidiRule
succ :: BidiRule -> BidiRule
$cpred :: BidiRule -> BidiRule
pred :: BidiRule -> BidiRule
$ctoEnum :: Int -> BidiRule
toEnum :: Int -> BidiRule
$cfromEnum :: BidiRule -> Int
fromEnum :: BidiRule -> Int
$cenumFrom :: BidiRule -> [BidiRule]
enumFrom :: BidiRule -> [BidiRule]
$cenumFromThen :: BidiRule -> BidiRule -> [BidiRule]
enumFromThen :: BidiRule -> BidiRule -> [BidiRule]
$cenumFromTo :: BidiRule -> BidiRule -> [BidiRule]
enumFromTo :: BidiRule -> BidiRule -> [BidiRule]
$cenumFromThenTo :: BidiRule -> BidiRule -> BidiRule -> [BidiRule]
enumFromThenTo :: BidiRule -> BidiRule -> BidiRule -> [BidiRule]
Enum, BidiRule
BidiRule -> BidiRule -> Bounded BidiRule
forall a. a -> a -> Bounded a
$cminBound :: BidiRule
minBound :: BidiRule
$cmaxBound :: BidiRule
maxBound :: BidiRule
Bounded, (forall x. BidiRule -> Rep BidiRule x)
-> (forall x. Rep BidiRule x -> BidiRule) -> Generic BidiRule
forall x. Rep BidiRule x -> BidiRule
forall x. BidiRule -> Rep BidiRule x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. BidiRule -> Rep BidiRule x
from :: forall x. BidiRule -> Rep BidiRule x
$cto :: forall x. Rep BidiRule x -> BidiRule
to :: forall x. Rep BidiRule x -> BidiRule
Generic)

instance NFData BidiRule

-- | Unicode script assignment.
--
-- Scripts are used for contextual validation of certain code points.
data Script
  = Latin
  | Greek
  | Cyrillic
  | Hebrew
  | Arabic
  | Devanagari
  | Bengali
  | Gurmukhi
  | Gujarati
  | Oriya
  | Tamil
  | Telugu
  | Kannada
  | Malayalam
  | Thai
  | Lao
  | Tibetan
  | Myanmar
  | Georgian
  | Hangul
  | Hiragana
  | Katakana
  | Han
  | OtherScript
  deriving (Int -> Script -> ShowS
[Script] -> ShowS
Script -> String
(Int -> Script -> ShowS)
-> (Script -> String) -> ([Script] -> ShowS) -> Show Script
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Script -> ShowS
showsPrec :: Int -> Script -> ShowS
$cshow :: Script -> String
show :: Script -> String
$cshowList :: [Script] -> ShowS
showList :: [Script] -> ShowS
Show, Script -> Script -> Bool
(Script -> Script -> Bool)
-> (Script -> Script -> Bool) -> Eq Script
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Script -> Script -> Bool
== :: Script -> Script -> Bool
$c/= :: Script -> Script -> Bool
/= :: Script -> Script -> Bool
Eq, Eq Script
Eq Script =>
(Script -> Script -> Ordering)
-> (Script -> Script -> Bool)
-> (Script -> Script -> Bool)
-> (Script -> Script -> Bool)
-> (Script -> Script -> Bool)
-> (Script -> Script -> Script)
-> (Script -> Script -> Script)
-> Ord Script
Script -> Script -> Bool
Script -> Script -> Ordering
Script -> Script -> Script
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Script -> Script -> Ordering
compare :: Script -> Script -> Ordering
$c< :: Script -> Script -> Bool
< :: Script -> Script -> Bool
$c<= :: Script -> Script -> Bool
<= :: Script -> Script -> Bool
$c> :: Script -> Script -> Bool
> :: Script -> Script -> Bool
$c>= :: Script -> Script -> Bool
>= :: Script -> Script -> Bool
$cmax :: Script -> Script -> Script
max :: Script -> Script -> Script
$cmin :: Script -> Script -> Script
min :: Script -> Script -> Script
Ord, Int -> Script
Script -> Int
Script -> [Script]
Script -> Script
Script -> Script -> [Script]
Script -> Script -> Script -> [Script]
(Script -> Script)
-> (Script -> Script)
-> (Int -> Script)
-> (Script -> Int)
-> (Script -> [Script])
-> (Script -> Script -> [Script])
-> (Script -> Script -> [Script])
-> (Script -> Script -> Script -> [Script])
-> Enum Script
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: Script -> Script
succ :: Script -> Script
$cpred :: Script -> Script
pred :: Script -> Script
$ctoEnum :: Int -> Script
toEnum :: Int -> Script
$cfromEnum :: Script -> Int
fromEnum :: Script -> Int
$cenumFrom :: Script -> [Script]
enumFrom :: Script -> [Script]
$cenumFromThen :: Script -> Script -> [Script]
enumFromThen :: Script -> Script -> [Script]
$cenumFromTo :: Script -> Script -> [Script]
enumFromTo :: Script -> Script -> [Script]
$cenumFromThenTo :: Script -> Script -> Script -> [Script]
enumFromThenTo :: Script -> Script -> Script -> [Script]
Enum, Script
Script -> Script -> Bounded Script
forall a. a -> a -> Bounded a
$cminBound :: Script
minBound :: Script
$cmaxBound :: Script
maxBound :: Script
Bounded, (forall x. Script -> Rep Script x)
-> (forall x. Rep Script x -> Script) -> Generic Script
forall x. Rep Script x -> Script
forall x. Script -> Rep Script x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Script -> Rep Script x
from :: forall x. Script -> Rep Script x
$cto :: forall x. Rep Script x -> Script
to :: forall x. Rep Script x -> Script
Generic)

instance NFData Script

-- | Punycode algorithm state per RFC 3492.
--
-- Internal state used during Punycode encoding/decoding. Not typically
-- needed by users of the library.
data PunycodeState = PunycodeState
  { PunycodeState -> Int
n :: {-# UNPACK #-}!Int
    -- ^ Next code point to encode
  , PunycodeState -> Int
delta :: {-# UNPACK #-}!Int
    -- ^ Delta value for encoding
  , PunycodeState -> Int
bias :: {-# UNPACK #-}!Int
    -- ^ Bias for variable-length integer encoding
  , PunycodeState -> Int
h :: {-# UNPACK #-}!Int
    -- ^ Number of code points handled
  }
  deriving (Int -> PunycodeState -> ShowS
[PunycodeState] -> ShowS
PunycodeState -> String
(Int -> PunycodeState -> ShowS)
-> (PunycodeState -> String)
-> ([PunycodeState] -> ShowS)
-> Show PunycodeState
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PunycodeState -> ShowS
showsPrec :: Int -> PunycodeState -> ShowS
$cshow :: PunycodeState -> String
show :: PunycodeState -> String
$cshowList :: [PunycodeState] -> ShowS
showList :: [PunycodeState] -> ShowS
Show, PunycodeState -> PunycodeState -> Bool
(PunycodeState -> PunycodeState -> Bool)
-> (PunycodeState -> PunycodeState -> Bool) -> Eq PunycodeState
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PunycodeState -> PunycodeState -> Bool
== :: PunycodeState -> PunycodeState -> Bool
$c/= :: PunycodeState -> PunycodeState -> Bool
/= :: PunycodeState -> PunycodeState -> Bool
Eq, (forall x. PunycodeState -> Rep PunycodeState x)
-> (forall x. Rep PunycodeState x -> PunycodeState)
-> Generic PunycodeState
forall x. Rep PunycodeState x -> PunycodeState
forall x. PunycodeState -> Rep PunycodeState x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PunycodeState -> Rep PunycodeState x
from :: forall x. PunycodeState -> Rep PunycodeState x
$cto :: forall x. Rep PunycodeState x -> PunycodeState
to :: forall x. Rep PunycodeState x -> PunycodeState
Generic)

instance NFData PunycodeState

-- | Initial Punycode state per RFC 3492.
--
-- Starting state for Punycode encoding operations.
initialState :: PunycodeState
initialState :: PunycodeState
initialState = PunycodeState
  { n :: Int
n = Int
0x80      -- Initial code point (128)
  , delta :: Int
delta = Int
0
  , bias :: Int
bias = Int
72     -- Initial bias
  , h :: Int
h = Int
0
  }

-- | Punycode algorithm parameters per RFC 3492.
--
-- Constants used in the Punycode algorithm. Not typically needed by users.
data PunycodeParams = PunycodeParams
  { PunycodeParams -> Int
base :: Int   -- ^ Base (36)
  , PunycodeParams -> Int
tmin :: Int   -- ^ Minimum threshold (1)
  , PunycodeParams -> Int
tmax :: Int   -- ^ Maximum threshold (26)
  , PunycodeParams -> Int
skew :: Int   -- ^ Skew (38)
  , PunycodeParams -> Int
damp :: Int   -- ^ Damp (700)
  }
  deriving (Int -> PunycodeParams -> ShowS
[PunycodeParams] -> ShowS
PunycodeParams -> String
(Int -> PunycodeParams -> ShowS)
-> (PunycodeParams -> String)
-> ([PunycodeParams] -> ShowS)
-> Show PunycodeParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> PunycodeParams -> ShowS
showsPrec :: Int -> PunycodeParams -> ShowS
$cshow :: PunycodeParams -> String
show :: PunycodeParams -> String
$cshowList :: [PunycodeParams] -> ShowS
showList :: [PunycodeParams] -> ShowS
Show, PunycodeParams -> PunycodeParams -> Bool
(PunycodeParams -> PunycodeParams -> Bool)
-> (PunycodeParams -> PunycodeParams -> Bool) -> Eq PunycodeParams
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: PunycodeParams -> PunycodeParams -> Bool
== :: PunycodeParams -> PunycodeParams -> Bool
$c/= :: PunycodeParams -> PunycodeParams -> Bool
/= :: PunycodeParams -> PunycodeParams -> Bool
Eq, (forall x. PunycodeParams -> Rep PunycodeParams x)
-> (forall x. Rep PunycodeParams x -> PunycodeParams)
-> Generic PunycodeParams
forall x. Rep PunycodeParams x -> PunycodeParams
forall x. PunycodeParams -> Rep PunycodeParams x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. PunycodeParams -> Rep PunycodeParams x
from :: forall x. PunycodeParams -> Rep PunycodeParams x
$cto :: forall x. Rep PunycodeParams x -> PunycodeParams
to :: forall x. Rep PunycodeParams x -> PunycodeParams
Generic)

instance NFData PunycodeParams

-- | Standard Punycode parameters from RFC 3492.
punycodeParams :: PunycodeParams
punycodeParams :: PunycodeParams
punycodeParams = PunycodeParams
  { base :: Int
base = Int
36
  , tmin :: Int
tmin = Int
1
  , tmax :: Int
tmax = Int
26
  , skew :: Int
skew = Int
38
  , damp :: Int
damp = Int
700
  }