From: David du Colombier <0intro@gmail.com> Date: Tue, 17 Dec 2013 22:19:11 +0000 (-0800) Subject: net: reimplement toLower to not depend on strings X-Git-Tag: go1.3beta1~1199 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=e87b1710138e512019cc2bb22420a15cc5336bf3;p=gostls13.git net: reimplement toLower to not depend on strings R=golang-dev, r, bradfitz CC=golang-dev, jas https://golang.org/cl/43610043 --- diff --git a/src/pkg/net/lookup_plan9.go b/src/pkg/net/lookup_plan9.go index 9874120851..8003d177d0 100644 --- a/src/pkg/net/lookup_plan9.go +++ b/src/pkg/net/lookup_plan9.go @@ -7,7 +7,6 @@ package net import ( "errors" "os" - "strings" ) func query(filename, query string, bufSize int) (res []string, err error) { @@ -70,10 +69,33 @@ func queryDNS(addr string, typ string) (res []string, err error) { return query("/net/dns", addr+" "+typ, 1024) } +// toLower returns a lower-case version of in. Restricting us to +// ASCII is sufficient to handle the IP protocol names and allow +// us to not depend on the strings and unicode packages. +func toLower(in string) string { + isAlreadyLowerCase := true + for _, c := range in { + if 'A' <= c && c <= 'Z' { + isAlreadyLowerCase = false + break + } + } + if isAlreadyLowerCase { + return in + } + out := []byte(in) + for i, c := range out { + if 'A' <= c && c <= 'Z' { + out[i] += 'a' - 'A' + } + } + return string(out) +} + // lookupProtocol looks up IP protocol name and returns // the corresponding protocol number. func lookupProtocol(name string) (proto int, err error) { - lines, err := query("/net/cs", "!protocol="+strings.ToLower(name), 128) + lines, err := query("/net/cs", "!protocol="+toLower(name), 128) if err != nil { return 0, err }