]> Sergey Matveev's repositories - tofuproxy.git/blob - tls/tolower.go
Lowercase domain names
[tofuproxy.git] / tls / tolower.go
1 package tofuproxy
2
3 import "unicode/utf8"
4
5 // Copy-pasted from crypto/x509, as it is not public.
6 func toLowerCaseASCII(in string) string {
7         isAlreadyLowerCase := true
8         for _, c := range in {
9                 if c == utf8.RuneError {
10                         isAlreadyLowerCase = false
11                         break
12                 }
13                 if 'A' <= c && c <= 'Z' {
14                         isAlreadyLowerCase = false
15                         break
16                 }
17         }
18         if isAlreadyLowerCase {
19                 return in
20         }
21         out := []byte(in)
22         for i, c := range out {
23                 if 'A' <= c && c <= 'Z' {
24                         out[i] += 'a' - 'A'
25                 }
26         }
27         return string(out)
28 }