1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-11-23 21:02:28 +01:00

Move punycode functions to client.go

This commit is contained in:
adnano 2021-02-21 09:43:23 -05:00
parent b90b5bf2dc
commit 787a2445a8
2 changed files with 23 additions and 28 deletions

@ -7,6 +7,9 @@ import (
"net" "net"
"net/url" "net/url"
"time" "time"
"unicode/utf8"
"golang.org/x/net/idna"
) )
// A Client is a Gemini client. Its zero value is a usable client. // A Client is a Gemini client. Its zero value is a usable client.
@ -202,3 +205,23 @@ func splitHostPort(hostport string) (host, port string) {
} }
return return
} }
func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] >= utf8.RuneSelf {
return false
}
}
return true
}
// punycodeHostname returns the punycoded version of hostname.
func punycodeHostname(hostname string) (string, error) {
if net.ParseIP(hostname) != nil {
return hostname, nil
}
if isASCII(hostname) {
return hostname, nil
}
return idna.Lookup.ToASCII(hostname)
}

@ -1,28 +0,0 @@
package gemini
import (
"net"
"unicode/utf8"
"golang.org/x/net/idna"
)
func isASCII(s string) bool {
for i := 0; i < len(s); i++ {
if s[i] >= utf8.RuneSelf {
return false
}
}
return true
}
// punycodeHostname returns the punycoded version of hostname.
func punycodeHostname(hostname string) (string, error) {
if net.ParseIP(hostname) != nil {
return hostname, nil
}
if isASCII(hostname) {
return hostname, nil
}
return idna.Lookup.ToASCII(hostname)
}