diff options
Diffstat (limited to 'libgo/go/regexp/syntax/regexp.go')
-rw-r--r-- | libgo/go/regexp/syntax/regexp.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/libgo/go/regexp/syntax/regexp.go b/libgo/go/regexp/syntax/regexp.go index adcfe294495..668a07764a1 100644 --- a/libgo/go/regexp/syntax/regexp.go +++ b/libgo/go/regexp/syntax/regexp.go @@ -303,3 +303,19 @@ func (re *Regexp) MaxCap() int { } return m } + +// CapNames walks the regexp to find the names of capturing groups. +func (re *Regexp) CapNames() []string { + names := make([]string, re.MaxCap()+1) + re.capNames(names) + return names +} + +func (re *Regexp) capNames(names []string) { + if re.Op == OpCapture { + names[re.Cap] = re.Name + } + for _, sub := range re.Sub { + sub.capNames(names) + } +} |