fixed StringWhile
This commit is contained in:
parent
40d00d9244
commit
ca6cf3d943
@ -84,8 +84,9 @@ func (r *Reader) UnreadString(str string) error {
|
|||||||
func (r *Reader) StringWhile(f func(rn rune) bool) (string, error) {
|
func (r *Reader) StringWhile(f func(rn rune) bool) (string, error) {
|
||||||
s := new(strings.Builder)
|
s := new(strings.Builder)
|
||||||
|
|
||||||
|
var rn rune
|
||||||
var err error
|
var err error
|
||||||
for rn, err := r.Rune(); err == nil && f(rn); rn, err = r.Rune() {
|
for rn, err = r.Rune(); err == nil && f(rn); rn, err = r.Rune() {
|
||||||
s.WriteRune(rn)
|
s.WriteRune(rn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,3 +22,15 @@ func TestPos(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEOF(t *testing.T) {
|
||||||
|
r := NewReader(strings.NewReader("hello world\nasddsa"))
|
||||||
|
|
||||||
|
for line, err := r.StringUntil(isNewline); err == nil; line, err = r.StringUntil(isNewline) {
|
||||||
|
fmt.Println(line, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isNewline(rn rune) bool {
|
||||||
|
return rn == '\n'
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user