From 25505b0ea21aa9db6dbee0fec7936e8b2cf49bd2 Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 14 Jul 2023 20:40:01 +0200 Subject: [PATCH] ExpectOneOfString returns bool if string was found --- errors.go | 1 - reader.go | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/errors.go b/errors.go index b0730e0..7152e3a 100644 --- a/errors.go +++ b/errors.go @@ -6,5 +6,4 @@ import ( var ( ErrNothingToUnread = adverr.NewErrTmpl("ErrNothingToUnread", "Unreading failed because there wasn't any Read yet") - ErrNoMatchFound = adverr.NewErrTmpl("ErrNoMatchFound", "no match found") ) diff --git a/reader.go b/reader.go index 628cc79..d8ece28 100644 --- a/reader.go +++ b/reader.go @@ -233,21 +233,21 @@ func (r *Reader) ExpectString(str string) (bool, error) { // ExpectOneOfString calls ExpectString for each string successively // and returns the string which first matched. +// The boolean value is true if any string was found. // The returned string will not be unread. -// If no string matches, ErrNoMatchFound is returned -func (r *Reader) ExpectOneOfString(str ...string) (string, error) { +func (r *Reader) ExpectOneOfString(str ...string) (string, bool, error) { for _, s := range str { ok, err := r.ExpectString(s) if err != nil { - return "", err + return "", false, err } if ok { - return s, nil + return s, true, nil } } - return "", ErrNoMatchFound.New() + return "", false, nil } // Commit clears the internal buffer and therefore removes all data which were already read.