]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - tls/tolower.go
Lowercase domain names
[tofuproxy.git] / tls / tolower.go
diff --git a/tls/tolower.go b/tls/tolower.go
new file mode 100644 (file)
index 0000000..321441e
--- /dev/null
@@ -0,0 +1,28 @@
+package tofuproxy
+
+import "unicode/utf8"
+
+// Copy-pasted from crypto/x509, as it is not public.
+func toLowerCaseASCII(in string) string {
+       isAlreadyLowerCase := true
+       for _, c := range in {
+               if c == utf8.RuneError {
+                       isAlreadyLowerCase = false
+                       break
+               }
+               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)
+}