unread rune on skip methods

This commit is contained in:
milarin 2023-01-21 00:37:14 +01:00
parent 1c9a3962ec
commit 31f5aa6e52

View File

@ -176,15 +176,23 @@ func (r *Reader) PeekStringUntil(f ...RuneFunc) (string, error) {
}
// SkipUntil acts as StringUntil but discards the string
// The rune for which that function returned false will be unread.
func (r *Reader) SkipUntil(f ...RuneFunc) error {
_, err := r.StringUntil(f...)
if err != nil {
return err
}
return r.UnreadRune()
}
// SkipWhile acts as StringWhile but discards the string
// SkipWhile acts as StringWhile but discards the string.
// The rune for which that function returned false will be unread.
func (r *Reader) SkipWhile(f ...RuneFunc) error {
_, err := r.StringWhile(f...)
if err != nil {
return err
}
return r.UnreadRune()
}
// ExpectRune returns true if any function returns true for the next rune read from r