v1.9.1
ADDED: * remap package
This commit is contained in:
parent
d9bd928edb
commit
154170c0e5
1
go.sum
1
go.sum
@ -10,3 +10,4 @@ golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
|||||||
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
|
||||||
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
|
r00t2.io/sysutils v1.14.0/go.mod h1:ZJ7gZxFVQ7QIokQ5fPZr7wl0XO5Iu+LqtE8j3ciRINw=
|
||||||
|
4
remap/doc.go
Normal file
4
remap/doc.go
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
/*
|
||||||
|
Package remap provides convenience functions around regular expressions.
|
||||||
|
*/
|
||||||
|
package remap
|
51
remap/funcs_remap.go
Normal file
51
remap/funcs_remap.go
Normal 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
|
||||||
|
}
|
10
remap/types.go
Normal file
10
remap/types.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package remap
|
||||||
|
|
||||||
|
import (
|
||||||
|
`regexp`
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReMap provides some map-related functions around a regexp.Regexp.
|
||||||
|
type ReMap struct {
|
||||||
|
*regexp.Regexp
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user