diff options
author | 2018-08-26 16:43:53 -0700 | |
---|---|---|
committer | 2018-08-26 16:43:53 -0700 | |
commit | a3f3f51c60e91f22cc57ecc23cf828421d46b6b7 (patch) | |
tree | e037378ae0ca1f09cfb0eb46e289f28f857c2aed /vendor/github.com/tdewolff/minify/xml/buffer.go | |
parent | a9e9c347f4d385b4a297a45be96cddfc3a1c7814 (diff) |
Migrate to go modules (Go 1.11)
Diffstat (limited to 'vendor/github.com/tdewolff/minify/xml/buffer.go')
-rw-r--r-- | vendor/github.com/tdewolff/minify/xml/buffer.go | 84 |
1 files changed, 0 insertions, 84 deletions
diff --git a/vendor/github.com/tdewolff/minify/xml/buffer.go b/vendor/github.com/tdewolff/minify/xml/buffer.go deleted file mode 100644 index d3ce61c..0000000 --- a/vendor/github.com/tdewolff/minify/xml/buffer.go +++ /dev/null @@ -1,84 +0,0 @@ -package xml // import "github.com/tdewolff/minify/xml" - -import "github.com/tdewolff/parse/xml" - -// Token is a single token unit with an attribute value (if given) and hash of the data. -type Token struct { - xml.TokenType - Data []byte - Text []byte - AttrVal []byte -} - -// TokenBuffer is a buffer that allows for token look-ahead. -type TokenBuffer struct { - l *xml.Lexer - - buf []Token - pos int -} - -// NewTokenBuffer returns a new TokenBuffer. -func NewTokenBuffer(l *xml.Lexer) *TokenBuffer { - return &TokenBuffer{ - l: l, - buf: make([]Token, 0, 8), - } -} - -func (z *TokenBuffer) read(t *Token) { - t.TokenType, t.Data = z.l.Next() - t.Text = z.l.Text() - if t.TokenType == xml.AttributeToken { - t.AttrVal = z.l.AttrVal() - } else { - t.AttrVal = nil - } -} - -// Peek returns the ith element and possibly does an allocation. -// Peeking past an error will panic. -func (z *TokenBuffer) Peek(pos int) *Token { - pos += z.pos - if pos >= len(z.buf) { - if len(z.buf) > 0 && z.buf[len(z.buf)-1].TokenType == xml.ErrorToken { - return &z.buf[len(z.buf)-1] - } - - c := cap(z.buf) - d := len(z.buf) - z.pos - p := pos - z.pos + 1 // required peek length - var buf []Token - if 2*p > c { - buf = make([]Token, 0, 2*c+p) - } else { - buf = z.buf - } - copy(buf[:d], z.buf[z.pos:]) - - buf = buf[:p] - pos -= z.pos - for i := d; i < p; i++ { - z.read(&buf[i]) - if buf[i].TokenType == xml.ErrorToken { - buf = buf[:i+1] - pos = i - break - } - } - z.pos, z.buf = 0, buf - } - return &z.buf[pos] -} - -// Shift returns the first element and advances position. -func (z *TokenBuffer) Shift() *Token { - if z.pos >= len(z.buf) { - t := &z.buf[:1][0] - z.read(t) - return t - } - t := &z.buf[z.pos] - z.pos++ - return t -} |