Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
25505b0ea2 | |||
4f269d0f29 | |||
e344b5973a |
@ -6,5 +6,4 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNothingToUnread = adverr.NewErrTmpl("ErrNothingToUnread", "Unreading failed because there wasn't any Read yet")
|
ErrNothingToUnread = adverr.NewErrTmpl("ErrNothingToUnread", "Unreading failed because there wasn't any Read yet")
|
||||||
ErrNoMatchFound = adverr.NewErrTmpl("ErrNoMatchFound", "no match found")
|
|
||||||
)
|
)
|
||||||
|
14
reader.go
14
reader.go
@ -47,6 +47,10 @@ func (r *Reader) Rune() (rune, error) {
|
|||||||
return rn, err
|
return rn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Reader) Buffered() int {
|
||||||
|
return r.src.Buffered()
|
||||||
|
}
|
||||||
|
|
||||||
// PeekRune returns the next rune in r without advancing reader position.
|
// PeekRune returns the next rune in r without advancing reader position.
|
||||||
// The next read will return the same rune again.
|
// The next read will return the same rune again.
|
||||||
func (r *Reader) PeekRune() (rune, error) {
|
func (r *Reader) PeekRune() (rune, error) {
|
||||||
@ -229,21 +233,21 @@ func (r *Reader) ExpectString(str string) (bool, error) {
|
|||||||
|
|
||||||
// ExpectOneOfString calls ExpectString for each string successively
|
// ExpectOneOfString calls ExpectString for each string successively
|
||||||
// and returns the string which first matched.
|
// and returns the string which first matched.
|
||||||
|
// The boolean value is true if any string was found.
|
||||||
// The returned string will not be unread.
|
// The returned string will not be unread.
|
||||||
// If no string matches, ErrNoMatchFound is returned
|
func (r *Reader) ExpectOneOfString(str ...string) (string, bool, error) {
|
||||||
func (r *Reader) ExpectOneOfString(str ...string) (string, error) {
|
|
||||||
for _, s := range str {
|
for _, s := range str {
|
||||||
ok, err := r.ExpectString(s)
|
ok, err := r.ExpectString(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if ok {
|
if ok {
|
||||||
return s, nil
|
return s, true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", ErrNoMatchFound
|
return "", false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit clears the internal buffer and therefore removes all data which were already read.
|
// Commit clears the internal buffer and therefore removes all data which were already read.
|
||||||
|
Reference in New Issue
Block a user