ADDED:
* remap package
This commit is contained in:
brent saner
2025-08-02 09:39:06 -04:00
parent d9bd928edb
commit 154170c0e5
4 changed files with 66 additions and 0 deletions

51
remap/funcs_remap.go Normal file
View File

@@ -0,0 +1,51 @@
package remap
/*
Map returns a map[string]<match bytes> for regexes with named capture groups matched in bytes b.
matches will be nil if no named capture group matches were found.
*/
func (r *ReMap) Map(b []byte) (matches map[string][]byte) {
var m [][]byte
var tmpMap map[string][]byte = make(map[string][]byte)
m = r.Regexp.FindSubmatch(b)
for idx, grpNm := range r.Regexp.SubexpNames() {
if idx != 0 && grpNm != "" {
tmpMap[grpNm] = m[idx]
}
}
if len(tmpMap) > 0 {
matches = tmpMap
}
return
}
/*
MapString returns a map[string]<match string> for regexes with named capture groups matched in string s.
matches will be nil if no named capture group matches were found.
*/
func (r *ReMap) MapString(s string) (matches map[string]string) {
var m []string
var tmpMap map[string]string = make(map[string]string)
m = r.Regexp.FindStringSubmatch(s)
for idx, grpNm := range r.Regexp.SubexpNames() {
if idx != 0 && grpNm != "" {
tmpMap[grpNm] = m[idx]
}
}
if len(tmpMap) > 0 {
matches = tmpMap
}
return
}