idn-0.1.2.0: Pure Haskell IDN and Punycode implementation
Safe HaskellNone
LanguageHaskell2010

Data.Text.Punycode

Description

Punycode encoding and decoding per RFC 3492.

Punycode is an encoding scheme used to represent Unicode strings in ASCII, primarily for use in Internationalized Domain Names (IDN). This module provides a pure Haskell implementation of the Punycode algorithm.

Example

>>> encode "münchen"
Right "mnchen-3ya"
>>> decode "mnchen-3ya"
Right "münchen"

See Also

  • IDN for high-level domain name processing
  • RFC 3492 for the full specification
Synopsis

Encoding and Decoding

encode :: Text -> Either PunycodeError Text Source #

Encode a Unicode string to Punycode.

Converts a Unicode string into its Punycode representation. The result contains only ASCII characters (a-z, 0-9, and the delimiter -) and can be safely used in contexts that require ASCII-only strings.

Examples

>>> encode "münchen"
Right "mnchen-3ya"
>>> encode "北京"
Right "1ci"

Errors

Returns Left with PunycodeError if: * The input contains invalid Unicode code points * Integer overflow occurs during encoding

Since: 0.1.0.0

decode :: Text -> Either PunycodeError Text Source #

Decode a Punycode string back to Unicode.

Converts a Punycode-encoded string back to its original Unicode representation. The input should contain only ASCII characters (a-z, 0-9, and -).

Examples

>>> decode "mnchen-3ya"
Right "münchen"
>>> decode "1ci"
Right "北京"

Errors

Returns Left with PunycodeError if: * The input is malformed Punycode * Integer overflow occurs during decoding

Since: 0.1.0.0

Error Types

data PunycodeError Source #

Punycode encoding/decoding errors.

These errors occur during low-level Punycode operations. For domain-level errors, see IDNError.

Constructors

InvalidPunycode Text

Malformed Punycode string with reason

Overflow

Integer overflow during encoding/decoding

Instances

Instances details
Generic PunycodeError Source # 
Instance details

Defined in Data.Text.IDN.Types

Associated Types

type Rep PunycodeError 
Instance details

Defined in Data.Text.IDN.Types

type Rep PunycodeError = D1 ('MetaData "PunycodeError" "Data.Text.IDN.Types" "idn-0.1.2.0-ECOO1RAUys73BxjjVgDeye" 'False) (C1 ('MetaCons "InvalidPunycode" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "Overflow" 'PrefixI 'False) (U1 :: Type -> Type))
Show PunycodeError Source # 
Instance details

Defined in Data.Text.IDN.Types

NFData PunycodeError Source # 
Instance details

Defined in Data.Text.IDN.Types

Methods

rnf :: PunycodeError -> () #

Eq PunycodeError Source # 
Instance details

Defined in Data.Text.IDN.Types

type Rep PunycodeError Source # 
Instance details

Defined in Data.Text.IDN.Types

type Rep PunycodeError = D1 ('MetaData "PunycodeError" "Data.Text.IDN.Types" "idn-0.1.2.0-ECOO1RAUys73BxjjVgDeye" 'False) (C1 ('MetaCons "InvalidPunycode" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "Overflow" 'PrefixI 'False) (U1 :: Type -> Type))