ExpectOneOfString returns bool if string was found
This commit is contained in:
parent
4f269d0f29
commit
25505b0ea2
@ -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")
|
||||
)
|
||||
|
10
reader.go
10
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.
|
||||
|
Loading…
Reference in New Issue
Block a user