| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.Text.Punycode
Contents
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
IDNfor high-level domain name processing- RFC 3492 for the full specification
Synopsis
- encode :: Text -> Either PunycodeError Text
- decode :: Text -> Either PunycodeError Text
- data PunycodeError
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 |