From 787a2445a8ffb535ba253dba49c78314358d987a Mon Sep 17 00:00:00 2001 From: adnano Date: Sun, 21 Feb 2021 09:43:23 -0500 Subject: [PATCH] Move punycode functions to client.go --- client.go | 23 +++++++++++++++++++++++ punycode.go | 28 ---------------------------- 2 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 punycode.go diff --git a/client.go b/client.go index 9d79832..97a35bb 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,9 @@ import ( "net" "net/url" "time" + "unicode/utf8" + + "golang.org/x/net/idna" ) // 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 } + +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) +} diff --git a/punycode.go b/punycode.go deleted file mode 100644 index 58f84e5..0000000 --- a/punycode.go +++ /dev/null @@ -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) -}