Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
ca24e1d5bf
|
|||
b156052e6f
|
|||
dda2418255
|
|||
8e40deae6a
|
@@ -21,6 +21,8 @@ if [ "$( git rev-parse --abbrev-ref HEAD )" != "master" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
git pull --ff
|
||||||
|
|
||||||
curr_vers=$(git describe --tags --abbrev=0 | sed 's/v//g')
|
curr_vers=$(git describe --tags --abbrev=0 | sed 's/v//g')
|
||||||
|
|
||||||
next_ver=$(echo "$curr_vers" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
|
next_ver=$(echo "$curr_vers" | awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}')
|
||||||
|
@@ -348,3 +348,11 @@ func ArrFlattenDirect[T1 any](arr [][]T1) []T1 {
|
|||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ArrCastToAny[T1 any](arr []T1) []any {
|
||||||
|
r := make([]any, len(arr))
|
||||||
|
for i, v := range arr {
|
||||||
|
r[i] = any(v)
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
package rext
|
package rext
|
||||||
|
|
||||||
import "regexp"
|
import (
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
type Regex interface {
|
type Regex interface {
|
||||||
IsMatch(haystack string) bool
|
IsMatch(haystack string) bool
|
||||||
@@ -29,6 +32,10 @@ type RegexMatchGroup struct {
|
|||||||
end int
|
end int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OptRegexMatchGroup struct {
|
||||||
|
v *RegexMatchGroup
|
||||||
|
}
|
||||||
|
|
||||||
func W(rex *regexp.Regexp) Regex {
|
func W(rex *regexp.Regexp) Regex {
|
||||||
return ®exWrapper{rex: rex, subnames: rex.SubexpNames()}
|
return ®exWrapper{rex: rex, subnames: rex.SubexpNames()}
|
||||||
}
|
}
|
||||||
@@ -97,7 +104,7 @@ func (m RegexMatch) GroupByIndex(idx int) RegexMatchGroup {
|
|||||||
return RegexMatchGroup{haystack: m.haystack, start: m.submatchesIndex[idx*2], end: m.submatchesIndex[idx*2+1]}
|
return RegexMatchGroup{haystack: m.haystack, start: m.submatchesIndex[idx*2], end: m.submatchesIndex[idx*2+1]}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupByName returns the value of a matched group (group 0 == whole match)
|
// GroupByName returns the value of a matched group (panics if not found!)
|
||||||
func (m RegexMatch) GroupByName(name string) RegexMatchGroup {
|
func (m RegexMatch) GroupByName(name string) RegexMatchGroup {
|
||||||
for idx, subname := range m.subnames {
|
for idx, subname := range m.subnames {
|
||||||
if subname == name {
|
if subname == name {
|
||||||
@@ -107,6 +114,16 @@ func (m RegexMatch) GroupByName(name string) RegexMatchGroup {
|
|||||||
panic("failed to find regex-group by name")
|
panic("failed to find regex-group by name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GroupByName returns the value of a matched group (returns empty OptRegexMatchGroup if not found)
|
||||||
|
func (m RegexMatch) GroupByNameOrEmpty(name string) OptRegexMatchGroup {
|
||||||
|
for idx, subname := range m.subnames {
|
||||||
|
if subname == name {
|
||||||
|
return OptRegexMatchGroup{&RegexMatchGroup{haystack: m.haystack, start: m.submatchesIndex[idx*2], end: m.submatchesIndex[idx*2+1]}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OptRegexMatchGroup{}
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (g RegexMatchGroup) Value() string {
|
func (g RegexMatchGroup) Value() string {
|
||||||
@@ -128,3 +145,47 @@ func (g RegexMatchGroup) Range() (int, int) {
|
|||||||
func (g RegexMatchGroup) Length() int {
|
func (g RegexMatchGroup) Length() int {
|
||||||
return g.end - g.start
|
return g.end - g.start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) Value() string {
|
||||||
|
return g.v.Value()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) ValueOrEmpty() string {
|
||||||
|
if g.v == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return g.v.Value()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) ValueOrNil() *string {
|
||||||
|
if g.v == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return langext.Ptr(g.v.Value())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) IsEmpty() bool {
|
||||||
|
return g.v == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) Exists() bool {
|
||||||
|
return g.v != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) Start() int {
|
||||||
|
return g.v.Start()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) End() int {
|
||||||
|
return g.v.End()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) Range() (int, int) {
|
||||||
|
return g.v.Range()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g OptRegexMatchGroup) Length() int {
|
||||||
|
return g.v.Length()
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user