Involved Source Filesgo118.go Package idna implements IDNA2008 using the compatibility processing
defined by UTS (Unicode Technical Standard) #46, which defines a standard to
deal with the transition from IDNA2003.
IDNA2008 (Internationalized Domain Names for Applications), is defined in RFC
5890, RFC 5891, RFC 5892, RFC 5893 and RFC 5894.
UTS #46 is defined in https://www.unicode.org/reports/tr46.
See https://unicode.org/cldr/utility/idna.jsp for a visualization of the
differences between these two standards.punycode.gotables15.0.0.gotrie.gotrie13.0.0.gotrieval.go
Package-Level Type Names (total 12, in which 2 are exported)
A Profile defines the configuration of an IDNA mapper.optionsoptions bidirule, if specified, checks whether s conforms to the Bidi Rule
defined in RFC 5893.options.checkHyphensbooloptions.checkJoinersbool fromPuny calls validation rules when converting A-labels to U-labels. mapping implements a validation and mapping step as defined in RFC 5895
or UTS 46, tailored to, for example, domain registration or lookup.options.removeLeadingDotsbooloptions.transitionalbooloptions.trie*idnaTrieoptions.useSTD3Rulesbooloptions.verifyDNSLengthbool String reports a string with a description of the profile for debugging
purposes. The string format may change with different versions. 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. 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. process implements the algorithm described in section 4 of UTS #46,
see https://www.unicode.org/reports/tr46.(*Profile) simplify(cat category) category validateLabel validates the criteria from Section 4.1. Item 1, 4, and 6 are
already implicitly satisfied by the overall implementation.
*Profile : fmt.Stringer
*Profile : context.stringer
*Profile : runtime.stringer
func New(o ...Option) *Profile
func normalize(p *Profile, s string) (mapped string, isBidi bool, err error)
func validateAndMap(p *Profile, s string) (vm string, bidi bool, err error)
func validateFromPunycode(p *Profile, s string) error
func validateRegistration(p *Profile, s string) (idem string, bidi bool, err error)
var Display *Profile
var Lookup *Profile
var Punycode *Profile
var Registration *Profile
var display *Profile
var lookup *Profile
var punycode *Profile
var registration *Profile
idnaTrie. Total size: 31598 bytes (30.86 KiB). Checksum: d3118eda0d6b5360. lookup returns the trie value for the first UTF-8 encoding in s and
the width in bytes of this encoding. The size will be 0 if s does not
hold enough bytes to complete the encoding. len(s) must be greater than 0. lookupString returns the trie value for the first UTF-8 encoding in s and
the width in bytes of this encoding. The size will be 0 if s does not
hold enough bytes to complete the encoding. len(s) must be greater than 0. lookupStringUnsafe returns the trie value for the first UTF-8 encoding in s.
s must start with a full and valid UTF-8 encoded rune. lookupUnsafe returns the trie value for the first UTF-8 encoding in s.
s must start with a full and valid UTF-8 encoded rune. lookupValue determines the type of block n and looks up the value for b.
func newIdnaTrie(i int) *idnaTrie
var trie *idnaTrie
info holds information from the IDNA mapping table for a single rune. It is
the value returned by a trie lookup. In most cases, all information fits in
a 16-bit value. For mappings, this value may contain an index into a slice
with the mapped string. Such mappings can consist of the actual mapped value
or an XOR pattern to be applied to the bytes of the UTF8 encoding of the
input rune. This technique is used by the cases packages and reduces the
table size significantly.
The per-rune values have the following format:
if mapped {
if inlinedXOR {
15..13 inline XOR marker
12..11 unused
10..3 inline XOR mask
} else {
15..3 index into xor or mapping table
}
} else {
15..14 unused
13 mayNeedNorm
12..11 attributes
10..8 joining type
7..3 category type
}
2 use xor pattern
1..0 mapped category
See the definitions below for a more detailed description of the various
bits. appendMapping appends the mapping for the respective rune. isMapped must be
true. A mapping is a categorization of a rune as defined in UTS #46.( info) category() category( info) isBidi(s string) bool( info) isMapped() bool( info) isModifier() bool( info) isViramaModifier() bool( info) joinType() info
offset[]uint16values[]valueRange lookup determines the type of block n and looks up the value for b.
For n < t.cutoff, the block is a simple lookup table. Otherwise, the block
is a list of ranges with an accompanying value. Given a matching range r,
the value for b is by r.value + (b - r.lo) * stride.
var idnaSparse
Package-Level Functions (total 27, in which 13 are exported)
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.
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.
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.
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.
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.
RemoveLeadingDots removes leading label separators. Leading runes that map to
dots, such as U+3002 IDEOGRAPHIC FULL STOP, are removed as well.
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.
ToASCII is a wrapper for Punycode.ToASCII.
ToUnicode is a wrapper for Punycode.ToUnicode.
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.
ValidateForRegistration sets validation options to verify that a given IDN is
properly formatted for registration as defined by Section 4 of RFC 5891.
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.
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.
adapt is the bias adaptation function specified in section 6.1.
encode encodes a string as specified in section 6.3 and prepends prefix to
the result.
The "while h < length(input)" line in the specification becomes "for
remaining != 0" in the Go code, because len(s) in Go is in bytes, not runes.
Package-Level Variables (total 18, in which 4 are exported)
Display is the recommended profile for displaying domain names.
The configuration of this profile may change over time.
Lookup is the recommended profile for looking up domain names, according
to Section 5 of RFC 5891. The exact configuration of this profile may
change over time.
Punycode is a Profile that does raw punycode processing with a minimum
of validation.
Registration is the recommended profile for checking whether a given
IDN is valid for registration, according to Section 4 of RFC 5891.
Package-Level Constants (total 48, in which 1 is exported)
UnicodeVersion is the Unicode version from which the tables in this package are derived.
acePrefix is the ASCII Compatible Encoding prefix.
Attributes
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
constinlineXOR = 57344 // These bits are set if the XOR pattern is inlined.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
These parameter values are specified in section 5.
All computation is done with int32s, so that overflow behavior is identical
regardless of whether int is 32-bit or 64-bit.
Transitional processing is disabled by default in Go 1.18.
https://golang.org/issue/47510
The pages are generated with Goldsv0.6.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.