You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
912 B
Go
45 lines
912 B
Go
2 years ago
|
package stt
|
||
|
|
||
|
import "bytes"
|
||
|
|
||
|
// ReadString read string from iterator
|
||
|
func (iter *Iterator) ReadString() (ret string) {
|
||
|
depthEnding := encryptBytes([]byte{'/'}, iter.depth)
|
||
|
depthEndingLen := len(depthEnding)
|
||
|
for i := iter.head; i < iter.tail; i++ {
|
||
|
if iter.depth > 1 {
|
||
|
if i+depthEndingLen >= iter.tail {
|
||
|
return
|
||
|
}
|
||
|
endings := iter.buf[i : i+depthEndingLen]
|
||
|
if bytes.Equal(endings, depthEnding) {
|
||
|
ret = string(iter.buf[iter.head:i])
|
||
|
iter.head = i
|
||
|
break
|
||
|
}
|
||
|
} else {
|
||
|
c := iter.buf[i]
|
||
|
if c == '/' {
|
||
|
ret = string(iter.buf[iter.head:i])
|
||
|
iter.head = i
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
ret = string(decryptBytes([]byte(ret), iter.depth))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func (iter *Iterator) ReadFieldName() (ret string) {
|
||
|
// key@=value/
|
||
|
for i := iter.head; i < iter.tail; i++ {
|
||
|
c := iter.buf[i]
|
||
|
if c == '@' {
|
||
|
ret = string(iter.buf[iter.head:i])
|
||
|
iter.head = i
|
||
|
return ret
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|