MCPcopy
hub / github.com/tdewolff/minify / Peek

Method Peek

html/buffer.go:67–98  ·  view source on GitHub ↗

Peek returns the ith element and possibly does an allocation. Peeking past an error will panic.

(pos int)

Source from the content-addressed store, hash-verified

65// Peek returns the ith element and possibly does an allocation.
66// Peeking past an error will panic.
67func (z *TokenBuffer) Peek(pos int) *Token {
68 pos += z.pos
69 if pos >= len(z.buf) {
70 if len(z.buf) > 0 && z.buf[len(z.buf)-1].TokenType == html.ErrorToken {
71 return &z.buf[len(z.buf)-1]
72 }
73
74 c := cap(z.buf)
75 d := len(z.buf) - z.pos
76 p := pos - z.pos + 1 // required peek length
77 var buf []Token
78 if 2*p > c {
79 buf = make([]Token, 0, 2*c+p)
80 } else {
81 buf = z.buf
82 }
83 copy(buf[:d], z.buf[z.pos:])
84
85 buf = buf[:p]
86 pos -= z.pos
87 for i := d; i < p; i++ {
88 z.read(&buf[i])
89 if buf[i].TokenType == html.ErrorToken {
90 buf = buf[:i+1]
91 pos = i
92 break
93 }
94 }
95 z.pos, z.buf = 0, buf
96 }
97 return &z.buf[pos]
98}
99
100// Shift returns the first element and advances position.
101func (z *TokenBuffer) Shift() *Token {

Callers 3

MinifyMethod · 0.95
TestBufferFunction · 0.95
AttributesMethod · 0.95

Calls 3

readMethod · 0.95
lenFunction · 0.85
copyFunction · 0.50

Tested by 1

TestBufferFunction · 0.76