MCPcopy
hub / github.com/caddyserver/caddy / NextBlock

Method NextBlock

caddyconfig/caddyfile/dispenser.go:167–192  ·  view source on GitHub ↗

NextBlock can be used as the condition of a for loop to load the next token as long as it opens a block or is already in a block nested more than initialNestingLevel. In other words, a loop over NextBlock() will iterate all tokens in the block assuming the next token is an open curly brace, until th

(initialNestingLevel int)

Source from the content-addressed store, hash-verified

165// Next(), as it is usually prudent to skip the initial
166// token.
167func (d *Dispenser) NextBlock(initialNestingLevel int) bool {
168 if d.nesting > initialNestingLevel {
169 if !d.Next() {
170 return false // should be EOF error
171 }
172 if d.Val() == "}" && !d.nextOnSameLine() {
173 d.nesting--
174 } else if d.Val() == "{" && !d.nextOnSameLine() {
175 d.nesting++
176 }
177 return d.nesting > initialNestingLevel
178 }
179 if !d.nextOnSameLine() { // block must open on same line
180 return false
181 }
182 if d.Val() != "{" {
183 d.cursor-- // roll back if not opening brace
184 return false
185 }
186 d.Next() // consume open curly brace
187 if d.Val() == "}" {
188 return false // open and then closed right away
189 }
190 d.nesting++
191 return true
192}
193
194// Nesting returns the current nesting level. Necessary
195// if using NextBlock()

Callers 15

doImportMethod · 0.95
NextSegmentMethod · 0.95
parseACMEServerFunction · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
unmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80
UnmarshalCaddyfileMethod · 0.80

Calls 3

NextMethod · 0.95
ValMethod · 0.95
nextOnSameLineMethod · 0.95

Tested by 1

TestDispenser_NextBlockFunction · 0.64