mirror of
https://github.com/miekg/dns.git
synced 2025-10-17 21:01:00 +02:00
Improve docs on the label functions
Explicitly mention that the domain s must be valid before given it to these functions. Fixes: 306
This commit is contained in:
parent
f89e57ed50
commit
84e9295e47
@ -8,6 +8,7 @@ package dns
|
|||||||
// The root label (.) returns nil. Note that using
|
// The root label (.) returns nil. Note that using
|
||||||
// strings.Split(s) will work in most cases, but does not handle
|
// strings.Split(s) will work in most cases, but does not handle
|
||||||
// escaped dots (\.) for instance.
|
// escaped dots (\.) for instance.
|
||||||
|
// s must be a syntactically valid domain name, see IsDomainName.
|
||||||
func SplitDomainName(s string) (labels []string) {
|
func SplitDomainName(s string) (labels []string) {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@ -46,6 +47,8 @@ func SplitDomainName(s string) (labels []string) {
|
|||||||
//
|
//
|
||||||
// www.miek.nl. and miek.nl. have two labels in common: miek and nl
|
// www.miek.nl. and miek.nl. have two labels in common: miek and nl
|
||||||
// www.miek.nl. and www.bla.nl. have one label in common: nl
|
// www.miek.nl. and www.bla.nl. have one label in common: nl
|
||||||
|
//
|
||||||
|
// s1 and s2 must be syntactically valid domain names.
|
||||||
func CompareDomainName(s1, s2 string) (n int) {
|
func CompareDomainName(s1, s2 string) (n int) {
|
||||||
s1 = Fqdn(s1)
|
s1 = Fqdn(s1)
|
||||||
s2 = Fqdn(s2)
|
s2 = Fqdn(s2)
|
||||||
@ -86,6 +89,7 @@ func CompareDomainName(s1, s2 string) (n int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CountLabel counts the the number of labels in the string s.
|
// CountLabel counts the the number of labels in the string s.
|
||||||
|
// s must be a syntactically valid domain name.
|
||||||
func CountLabel(s string) (labels int) {
|
func CountLabel(s string) (labels int) {
|
||||||
if s == "." {
|
if s == "." {
|
||||||
return
|
return
|
||||||
@ -103,8 +107,8 @@ func CountLabel(s string) (labels int) {
|
|||||||
|
|
||||||
// Split splits a name s into its label indexes.
|
// Split splits a name s into its label indexes.
|
||||||
// www.miek.nl. returns []int{0, 4, 9}, www.miek.nl also returns []int{0, 4, 9}.
|
// www.miek.nl. returns []int{0, 4, 9}, www.miek.nl also returns []int{0, 4, 9}.
|
||||||
// .www.miek.nl. returns []int{0, 1, 5, 10}
|
// The root name (.) returns nil. Also see SplitDomainName.
|
||||||
// The root name (.) returns nil. Also see SplitDomainName.
|
// s must be a syntactically valid domain name.
|
||||||
func Split(s string) []int {
|
func Split(s string) []int {
|
||||||
if s == "." {
|
if s == "." {
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user