diff options
| author | Paul Chaignon <paul.chaignon@gmail.com> | 2023-11-10 15:58:33 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2023-11-13 13:40:05 +0000 |
| commit | 78b9d1a14311a5bd82c219eb4fa815a54ad832bd (patch) | |
| tree | 653928926e400e4a58f28298582e7af49a79279a /prog/encoding.go | |
| parent | 2c161a91dd08a981de82d650b264177c46b51e10 (diff) | |
prog: add helper function parser.HasNext
This helper function will be used in a subsequent commit to take a look
ahead at several characters.
Signed-off-by: Paul Chaignon <paul.chaignon@gmail.com>
Diffstat (limited to 'prog/encoding.go')
| -rw-r--r-- | prog/encoding.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/prog/encoding.go b/prog/encoding.go index 2216955d8..be883645b 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -1180,6 +1180,21 @@ func (p *parser) Char() byte { return p.s[p.i] } +func (p *parser) HasNext(str string) bool { + if p.e != nil { + return false + } + if len(p.s) < p.i+len(str) { + return false + } + for i := 0; i < len(str); i++ { + if p.s[p.i+i] != str[i] { + return false + } + } + return true +} + func (p *parser) Parse(ch byte) { if p.e != nil { return |
