// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.// Copyright 2016 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package idna// This file implements the Punycode algorithm from RFC 3492.import ()// 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.const (baseint32 = 36dampint32 = 700initialBiasint32 = 72initialNint32 = 128skewint32 = 38tmaxint32 = 26tminint32 = 1)func ( string) error { return &labelError{, "A3"} }// decode decodes a string as specified in section 6.2.func ( string) (string, error) {if == "" {return"", nil } := 1 + strings.LastIndex(, "-")if == 1 {return"", punyError() }if == len() {return [:len()-1], nil } := make([]rune, 0, len())if != 0 {for , := range [:-1] { = append(, ) } } , , := int32(0), initialN, initialBias := falsefor < len() { , := , int32(1)for := base; ; += base {if == len() {return"", punyError() } , := decodeDigit([])if ! {return"", punyError() } ++ , = madd(, , )if {return"", punyError() } := - if <= { = tmin } elseif >= +tmax { = tmax }if < {break } , = madd(0, , base-)if {return"", punyError() } }iflen() >= 1024 {return"", punyError() } := int32(len() + 1) = adapt(-, , == 0) += / %= if < 0 || > utf8.MaxRune {return"", punyError() } = append(, 0)copy([+1:], [:]) [] = ++ }returnstring(), nil}// 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.func (, string) (string, error) { := make([]byte, len(), len()+1+2*len())copy(, ) , , := int32(0), initialN, initialBias , := int32(0), int32(0)for , := range {if < 0x80 { ++ = append(, byte()) } else { ++ } } := if > 0 { = append(, '-') } := falsefor != 0 { := int32(0x7fffffff)for , := range {if > && >= { = } } , = madd(, -, +1)if {return"", punyError() } = for , := range {if < { ++if < 0 {return"", punyError() }continue }if > {continue } := for := base; ; += base { := - if <= { = tmin } elseif >= +tmax { = tmax }if < {break } = append(, encodeDigit(+(-)%(base-))) = ( - ) / (base - ) } = append(, encodeDigit()) = adapt(, +1, == ) = 0 ++ -- } ++ ++ }returnstring(), nil}// madd computes a + (b * c), detecting overflow.func (, , int32) ( int32, bool) { := int64() * int64()if > math.MaxInt32-int64() {return0, true }return + int32(), false}func ( byte) ( int32, bool) {switch {case'0' <= && <= '9':returnint32( - ('0' - 26)), truecase'A' <= && <= 'Z':returnint32( - 'A'), truecase'a' <= && <= 'z':returnint32( - 'a'), true }return0, false}func ( int32) byte {switch {case0 <= && < 26:returnbyte( + 'a')case26 <= && < 36:returnbyte( + ('0' - 26)) }panic("idna: internal error in punycode encoding")}// adapt is the bias adaptation function specified in section 6.1.func (, int32, bool) int32 {if { /= damp } else { /= 2 } += / := int32(0)for > ((base-tmin)*tmax)/2 { /= base - tmin += base }return + (base-tmin+1)*/(+skew)}
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.