diff options
author | 2024-11-08 13:51:23 +0000 | |
---|---|---|
committer | 2024-11-08 13:51:23 +0000 | |
commit | 29007b1b886e7455ece5aa6e4d477805209fad88 (patch) | |
tree | 21b11cbf12faf71d44d43c61a2d4916b7bd82b80 /vendor/github.com/uptrace/bun/internal/parser/parser.go | |
parent | bump ncruces/go-sqlite3 to v0.20.2 (#3524) (diff) | |
download | gotosocial-29007b1b886e7455ece5aa6e4d477805209fad88.tar.xz |
[chore] update bun libraries to v1.2.5 (#3528)
* update bun libraries to v1.2.5
* pin old v1.29.0 of otel
Diffstat (limited to 'vendor/github.com/uptrace/bun/internal/parser/parser.go')
-rw-r--r-- | vendor/github.com/uptrace/bun/internal/parser/parser.go | 50 |
1 files changed, 39 insertions, 11 deletions
diff --git a/vendor/github.com/uptrace/bun/internal/parser/parser.go b/vendor/github.com/uptrace/bun/internal/parser/parser.go index cdfc0be16..1f2704478 100644 --- a/vendor/github.com/uptrace/bun/internal/parser/parser.go +++ b/vendor/github.com/uptrace/bun/internal/parser/parser.go @@ -2,6 +2,8 @@ package parser import ( "bytes" + "fmt" + "io" "strconv" "github.com/uptrace/bun/internal" @@ -22,23 +24,43 @@ func NewString(s string) *Parser { return New(internal.Bytes(s)) } +func (p *Parser) Reset(b []byte) { + p.b = b + p.i = 0 +} + func (p *Parser) Valid() bool { return p.i < len(p.b) } -func (p *Parser) Bytes() []byte { +func (p *Parser) Remaining() []byte { return p.b[p.i:] } +func (p *Parser) ReadByte() (byte, error) { + if p.Valid() { + ch := p.b[p.i] + p.Advance() + return ch, nil + } + return 0, io.ErrUnexpectedEOF +} + func (p *Parser) Read() byte { if p.Valid() { - c := p.b[p.i] + ch := p.b[p.i] p.Advance() - return c + return ch } return 0 } +func (p *Parser) Unread() { + if p.i > 0 { + p.i-- + } +} + func (p *Parser) Peek() byte { if p.Valid() { return p.b[p.i] @@ -50,19 +72,25 @@ func (p *Parser) Advance() { p.i++ } -func (p *Parser) Skip(skip byte) bool { - if p.Peek() == skip { +func (p *Parser) Skip(skip byte) error { + ch := p.Peek() + if ch == skip { p.Advance() - return true + return nil } - return false + return fmt.Errorf("got %q, wanted %q", ch, skip) } -func (p *Parser) SkipBytes(skip []byte) bool { - if len(skip) > len(p.b[p.i:]) { - return false +func (p *Parser) SkipPrefix(skip []byte) error { + if !bytes.HasPrefix(p.b[p.i:], skip) { + return fmt.Errorf("got %q, wanted prefix %q", p.b, skip) } - if !bytes.Equal(p.b[p.i:p.i+len(skip)], skip) { + p.i += len(skip) + return nil +} + +func (p *Parser) CutPrefix(skip []byte) bool { + if !bytes.HasPrefix(p.b[p.i:], skip) { return false } p.i += len(skip) |