Module encoding/punycode

encoding/punycode

Punycode encoding/decoding (RFC 3492) for internationalized domain names.

Provides punycode encoding/decoding and IDN hostname conversion.

Example

{ punycode_decode, punycode_encode, to_unicode, to_ascii } :: import "std/encoding/punycode";

encoded := punycode_encode(`München`);
decoded := punycode_decode(encoded);
ascii_domain := to_ascii(`münchen.de`);  // "xn--mnchen-3ya.de"
unicode_domain := to_unicode(ascii_domain);  // "münchen.de"

Functions

punycode_decode function
fn(input : String) -> Option(String)

Decode a punycode-encoded string (without the xn-- prefix).

Returns .Some(decoded) on success, .None on invalid input.

Parameters

NameTypeNotes
inputString

Returns: Option(String)

punycode_encode function
fn(input : String) -> String

Encode a Unicode string to punycode (without the xn-- prefix).

Parameters

NameTypeNotes
inputString

Returns: String

to_unicode function
fn(hostname : String) -> String

Convert an IDN hostname to Unicode display form.

Splits on ., decodes xn-- labels via punycode, and keeps original labels on failure.

Parameters

NameTypeNotes
hostnameString

Returns: String

to_ascii function
fn(hostname : String) -> String

Convert a Unicode hostname to ASCII-compatible encoding.

Non-ASCII labels are punycode-encoded with the xn-- prefix.

Parameters

NameTypeNotes
hostnameString

Returns: String