From 31f5aa6e523567a9bc7f551ed47b18ae1915ec99 Mon Sep 17 00:00:00 2001 From: milarin Date: Sat, 21 Jan 2023 00:37:14 +0100 Subject: [PATCH] unread rune on skip methods --- reader.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/reader.go b/reader.go index 7329593..aef8bcf 100644 --- a/reader.go +++ b/reader.go @@ -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...) - return err + 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...) - return err + if err != nil { + return err + } + return r.UnreadRune() } // ExpectRune returns true if any function returns true for the next rune read from r