// ToASCII is a wrapper for Punycode.ToASCII. func ToASCII(s string) (string, error) { … } // ToUnicode is a wrapper for Punycode.ToUnicode. func ToUnicode(s string) (string, error) { … } type Option … // Transitional sets a Profile to use the Transitional mapping as defined in UTS // #46. This will cause, for example, "ß" to be mapped to "ss". Using the // transitional mapping provides a compromise between IDNA2003 and IDNA2008 // compatibility. It is used by some browsers when resolving domain names. This // option is only meaningful if combined with MapForLookup. func Transitional(transitional bool) Option { … } // VerifyDNSLength sets whether a Profile should fail if any of the IDN parts // are longer than allowed by the RFC. // // This option corresponds to the VerifyDnsLength flag in UTS #46. func VerifyDNSLength(verify bool) Option { … } // RemoveLeadingDots removes leading label separators. Leading runes that map to // dots, such as U+3002 IDEOGRAPHIC FULL STOP, are removed as well. func RemoveLeadingDots(remove bool) Option { … } // ValidateLabels sets whether to check the mandatory label validation criteria // as defined in Section 5.4 of RFC 5891. This includes testing for correct use // of hyphens ('-'), normalization, validity of runes, and the context rules. // In particular, ValidateLabels also sets the CheckHyphens and CheckJoiners flags // in UTS #46. func ValidateLabels(enable bool) Option { … } // CheckHyphens sets whether to check for correct use of hyphens ('-') in // labels. Most web browsers do not have this option set, since labels such as // "r3---sn-apo3qvuoxuxbt-j5pe" are in common use. // // This option corresponds to the CheckHyphens flag in UTS #46. func CheckHyphens(enable bool) Option { … } // CheckJoiners sets whether to check the ContextJ rules as defined in Appendix // A of RFC 5892, concerning the use of joiner runes. // // This option corresponds to the CheckJoiners flag in UTS #46. func CheckJoiners(enable bool) Option { … } // StrictDomainName limits the set of permissible ASCII characters to those // allowed in domain names as defined in RFC 1034 (A-Z, a-z, 0-9 and the // hyphen). This is set by default for MapForLookup and ValidateForRegistration, // but is only useful if ValidateLabels is set. // // This option is useful, for instance, for browsers that allow characters // outside this range, for example a '_' (U+005F LOW LINE). See // http://www.rfc-editor.org/std/std3.txt for more details. // // This option corresponds to the UseSTD3ASCIIRules flag in UTS #46. func StrictDomainName(use bool) Option { … } // BidiRule enables the Bidi rule as defined in RFC 5893. Any application // that relies on proper validation of labels should include this rule. // // This option corresponds to the CheckBidi flag in UTS #46. func BidiRule() Option { … } // ValidateForRegistration sets validation options to verify that a given IDN is // properly formatted for registration as defined by Section 4 of RFC 5891. func ValidateForRegistration() Option { … } // MapForLookup sets validation and mapping options such that a given IDN is // transformed for domain name lookup according to the requirements set out in // Section 5 of RFC 5891. The mappings follow the recommendations of RFC 5894, // RFC 5895 and UTS 46. It does not add the Bidi Rule. Use the BidiRule option // to add this check. // // The mappings include normalization and mapping case, width and other // compatibility mappings. func MapForLookup() Option { … } type options … type Profile … func apply(o *options, opts []Option) { … } // New creates a new Profile. // // With no options, the returned Profile is the most permissive and equals the // Punycode Profile. Options can be passed to further restrict the Profile. The // MapForLookup and ValidateForRegistration options set a collection of options, // for lookup and registration purposes respectively, which can be tailored by // adding more fine-grained options, where later options override earlier // options. func New(o ...Option) *Profile { … } // ToASCII converts a domain or domain label to its ASCII form. For example, // ToASCII("bücher.example.com") is "xn--bcher-kva.example.com", and // ToASCII("golang") is "golang". If an error is encountered it will return // an error and a (partially) processed result. func (p *Profile) ToASCII(s string) (string, error) { … } // ToUnicode converts a domain or domain label to its Unicode form. For example, // ToUnicode("xn--bcher-kva.example.com") is "bücher.example.com", and // ToUnicode("golang") is "golang". If an error is encountered it will return // an error and a (partially) processed result. func (p *Profile) ToUnicode(s string) (string, error) { … } // String reports a string with a description of the profile for debugging // purposes. The string format may change with different versions. func (p *Profile) String() string { … } var Punycode … var Lookup … var Display … var Registration … var punycode … var lookup … var display … var registration … type labelError … func (e labelError) code() string { … } func (e labelError) Error() string { … } type runeError … func (e runeError) code() string { … } func (e runeError) Error() string { … } // process implements the algorithm described in section 4 of UTS #46, // see https://www.unicode.org/reports/tr46. func (p *Profile) process(s string, toASCII bool) (string, error) { … } func normalize(p *Profile, s string) (mapped string, isBidi bool, err error) { … } func validateRegistration(p *Profile, s string) (idem string, bidi bool, err error) { … } func (c info) isBidi(s string) bool { … } func validateAndMap(p *Profile, s string) (vm string, bidi bool, err error) { … } type labelIter … func (l *labelIter) reset() { … } func (l *labelIter) done() bool { … } func (l *labelIter) result() string { … } func (l *labelIter) label() string { … } // next sets the value to the next label. It skips the last label if it is empty. func (l *labelIter) next() { … } func (l *labelIter) set(s string) { … } const acePrefix … func (p *Profile) simplify(cat category) category { … } func validateFromPunycode(p *Profile, s string) error { … } const zwnj … const zwj … type joinState … const stateStart … const stateVirama … const stateBefore … const stateBeforeVirama … const stateAfter … const stateFAIL … var joinStates … // validateLabel validates the criteria from Section 4.1. Item 1, 4, and 6 are // already implicitly satisfied by the overall implementation. func (p *Profile) validateLabel(s string) (err error) { … } func ascii(s string) bool { … }