mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-05 09:06:58 +02:00
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// See:
|
|
// - https://golang.org/LICENSE
|
|
// - https://golang.org/src/crypto/x509/verify.go
|
|
|
|
package source
|
|
|
|
import (
|
|
"unicode/utf8"
|
|
)
|
|
|
|
// toLowerCaseASCII returns a lower-case version of in. See RFC 6125 6.4.1. We use
|
|
// an explicitly ASCII function to avoid any sharp corners resulting from
|
|
// performing Unicode operations on DNS labels.
|
|
func toLowerCaseASCII(in string) string {
|
|
// If the string is already lower-case then there's nothing to do.
|
|
isAlreadyLowerCase := true
|
|
for _, c := range in {
|
|
if c == utf8.RuneError {
|
|
// If we get a UTF-8 error then there might be
|
|
// upper-case ASCII bytes in the invalid sequence.
|
|
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)
|
|
}
|