One more helper function for compression
This commit is contained in:
parent
8f8633d9a0
commit
79d092bd29
|
@ -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()
|
||||
}
|
||||
|
|
16
labels.go
16
labels.go
|
@ -48,3 +48,19 @@ func CompareLabels(s1, s2 string) (n int) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
// This function is needed for easy handling of compression
|
||||
// pointers
|
||||
// www.miek.nl, 2, gives that start of miek.nl (which is
|
||||
// 2 labels from the right)
|
||||
// labeloffset of zero is fishy as is a labeloffset larger
|
||||
// than the number of labels... TODO: make it an error?
|
||||
func offsetLabelFromRight(s string, labeloffset int) int {
|
||||
l := SplitLabels(s)
|
||||
fromleft := len(l) - labeloffset
|
||||
off := 0
|
||||
for i := 0; i < fromleft; i++ {
|
||||
off += len(l[i]) + 1
|
||||
}
|
||||
return off
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue