Add the first of faster/mem eff. labsl functions

This commit is contained in:
Miek Gieben 2013-06-20 07:49:18 +01:00
parent a317648fa3
commit cb1a259368
1 changed files with 28 additions and 0 deletions

View File

@ -87,3 +87,31 @@ func LenLabels(s string) (labels int) {
}
return
}
// NextLabel returns the index of the start of the next label in the
// string s. The bool end is true when the end of the string has been
// reached.
func nextLabel(s string, offset int) (i int, end bool) {
// The other label function are quite generous with memory,
// this one does not allocate.
quote := false
for i = 0; i < len(s); i++ {
switch s[i] {
case '\\':
quote = true
default:
quote = false
case '.':
if quote {
quote = !quote
continue
}
return i, false
}
}
return i, true
}