MCPcopy
hub / github.com/gorilla/mux / braceIndices

Function braceIndices

regexp.go:284–305  ·  view source on GitHub ↗

braceIndices returns the first level curly brace indices from a string. It returns an error in case of unbalanced braces.

(s string)

Source from the content-addressed store, hash-verified

282// braceIndices returns the first level curly brace indices from a string.
283// It returns an error in case of unbalanced braces.
284func braceIndices(s string) ([]int, error) {
285 var level, idx int
286 var idxs []int
287 for i := 0; i < len(s); i++ {
288 switch s[i] {
289 case '{':
290 if level++; level == 1 {
291 idx = i
292 }
293 case '}':
294 if level--; level == 0 {
295 idxs = append(idxs, idx, i+1)
296 } else if level < 0 {
297 return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
298 }
299 }
300 }
301 if level != 0 {
302 return nil, fmt.Errorf("mux: unbalanced braces in %q", s)
303 }
304 return idxs, nil
305}
306
307// varGroupName builds a capturing group name for the indexed variable.
308func varGroupName(idx int) string {

Callers 1

newRouteRegexpFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected