encoding.punycode #
Package punycode implements the Punycode encoding described in RFC 3492, the ASCII-compatible encoding used by internationalised domain names.
Punycode is an instance of the more general Bootstring encoding, tuned for Unicode code points and host name labels. It rewrites a string of arbitrary code points as a string of basic ASCII code points, so that names outside the ASCII range survive protocols that only accept ASCII.
This module encodes and decodes single labels. It performs no IDNA processing: it does not add or strip the xn-- prefix, does not case fold and does not normalise. Callers doing IDNA are expected to handle those steps themselves.
fn decode #
fn decode(input string) !string
decode returns the string that input encodes, expecting input without the xn-- prefix.
Both letter cases are accepted, as RFC 3492 requires of a decoder.
fn encode #
fn encode(input string) !string
encode returns the Punycode form of input, without the xn-- prefix.
The basic code points of input are emitted first, in order, followed by a delimiter if there were any, followed by the deltas that reinsert the remaining code points. Encoding a string that is already entirely ASCII therefore appends a trailing delimiter, which is what the format requires and what an IDNA layer is expected to avoid asking for.