diff --git a/label_test.go b/label_test.go index 4749b556..ab3a3252 100644 --- a/label_test.go +++ b/label_test.go @@ -28,3 +28,14 @@ func TestCompareLabels(t *testing.T) { t.Fail() } } + +func TestOffLabelFromRight(t *testing.T) { + s1 := "www.miek.nl" // fqdn?? + + t.Log(offsetLabelFromRight(s1, 4)) + t.Log(offsetLabelFromRight(s1, 3)) + t.Log(offsetLabelFromRight(s1, 2)) + t.Log(offsetLabelFromRight(s1, 1)) + t.Log(offsetLabelFromRight(s1, 0)) +// t.Fail() +} diff --git a/labels.go b/labels.go index 7979dad2..97d97c41 100644 --- a/labels.go +++ b/labels.go @@ -6,15 +6,15 @@ package dns func SplitLabels(s string) []string { last := byte('.') k := 0 - labels := make([]string, 0) - s = Fqdn(s) // Make fully qualified + labels := make([]string, 0) + s = Fqdn(s) // Make fully qualified for i := 0; i < len(s); i++ { if s[i] == '.' { if last == '\\' { // do nothing break } - labels = append(labels,s[k:i]) + labels = append(labels, s[k:i]) k = i + 1 // + dot } last = s[i] @@ -24,7 +24,7 @@ func SplitLabels(s string) []string { // CompareLabels compares the strings s1 and s2 and // returns how many labels they have in common starting from the right. -// The comparison stops at the first inequality +// The comparison stops at the first inequality. // // 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 @@ -32,19 +32,19 @@ func CompareLabels(s1, s2 string) (n int) { l1 := SplitLabels(s1) l2 := SplitLabels(s2) - x1 := len(l1)-1 - x2 := len(l2)-1 + x1 := len(l1) - 1 + x2 := len(l2) - 1 for { - if x1 < 0 || x2 < 0 { - break - } - if l1[x1] == l2[x2] { - n++ - } else { - break - } - x1-- - x2-- + if x1 < 0 || x2 < 0 { + break + } + if l1[x1] == l2[x2] { + n++ + } else { + break + } + x1-- + x2-- } - return + return }