1 // Copyright 2017 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
10 "golang.org/x/text/internal/export/idna"
13 func ExampleProfile() {
14 // Raw Punycode has no restrictions and does no mappings.
15 fmt.Println(idna.ToASCII(""))
16 fmt.Println(idna.ToASCII("*.faß.com"))
17 fmt.Println(idna.Punycode.ToASCII("*.faß.com"))
19 // Rewrite IDN for lookup. This (currently) uses transitional mappings to
20 // find a balance between IDNA2003 and IDNA2008 compatibility.
21 fmt.Println(idna.Lookup.ToASCII(""))
22 fmt.Println(idna.Lookup.ToASCII("www.faß.com"))
24 // Convert an IDN to ASCII for registration purposes. This changes the
25 // encoding, but reports an error if the input was illformed.
26 fmt.Println(idna.Registration.ToASCII(""))
27 fmt.Println(idna.Registration.ToASCII("www.faß.com"))
31 // *.xn--fa-hia.com <nil>
32 // *.xn--fa-hia.com <nil>
35 // idna: invalid label ""
36 // www.xn--fa-hia.com <nil>
42 // Raw Punycode has no restrictions and does no mappings.
44 fmt.Println(p.ToASCII("*.faß.com"))
46 // Do mappings. Note that star is not allowed in a DNS lookup.
49 idna.Transitional(true)) // Map ß -> ss
50 fmt.Println(p.ToASCII("*.faß.com"))
52 // Lookup for registration. Also does not allow '*'.
53 p = idna.New(idna.ValidateForRegistration())
54 fmt.Println(p.ToUnicode("*.faß.com"))
56 // Set up a profile maps for lookup, but allows wild cards.
59 idna.Transitional(true), // Map ß -> ss
60 idna.StrictDomainName(false)) // Set more permissive ASCII rules.
61 fmt.Println(p.ToASCII("*.faß.com"))
64 // *.xn--fa-hia.com <nil>
65 // *.fass.com idna: disallowed rune U+002A
66 // *.faß.com idna: disallowed rune U+002A