Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
b156052e6f
|
|||
dda2418255
|
|||
8e40deae6a
|
|||
289b9f47a2
|
|||
007c44df85 |
@@ -21,6 +21,8 @@ if [ "$( git rev-parse --abbrev-ref HEAD )" != "master" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git pull --ff
|
||||
|
||||
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}')
|
||||
|
@@ -265,6 +265,26 @@ func ArrMap[T1 any, T2 any](arr []T1, conv func(v T1) T2) []T2 {
|
||||
return r
|
||||
}
|
||||
|
||||
func MapMap[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) TR) []TR {
|
||||
r := make([]TR, 0, len(inmap))
|
||||
for k, v := range inmap {
|
||||
r = append(r, conv(k, v))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func MapMapErr[TK comparable, TV any, TR any](inmap map[TK]TV, conv func(k TK, v TV) (TR, error)) ([]TR, error) {
|
||||
r := make([]TR, 0, len(inmap))
|
||||
for k, v := range inmap {
|
||||
elem, err := conv(k, v)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, elem)
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func ArrMapExt[T1 any, T2 any](arr []T1, conv func(idx int, v T1) T2) []T2 {
|
||||
r := make([]T2, len(arr))
|
||||
for i, v := range arr {
|
||||
|
@@ -60,3 +60,12 @@ func CoalesceStringer(s fmt.Stringer, def string) string {
|
||||
return s.String()
|
||||
}
|
||||
}
|
||||
|
||||
func SafeCast[T any](v any, def T) T {
|
||||
switch r := v.(type) {
|
||||
case T:
|
||||
return r
|
||||
default:
|
||||
return def
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,9 @@
|
||||
package rext
|
||||
|
||||
import "regexp"
|
||||
import (
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
type Regex interface {
|
||||
IsMatch(haystack string) bool
|
||||
@@ -29,6 +32,10 @@ type RegexMatchGroup struct {
|
||||
end int
|
||||
}
|
||||
|
||||
type OptRegexMatchGroup struct {
|
||||
v *RegexMatchGroup
|
||||
}
|
||||
|
||||
func W(rex *regexp.Regexp) Regex {
|
||||
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]}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
for idx, subname := range m.subnames {
|
||||
if subname == name {
|
||||
@@ -107,6 +114,16 @@ func (m RegexMatch) GroupByName(name string) RegexMatchGroup {
|
||||
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 {
|
||||
@@ -128,3 +145,47 @@ func (g RegexMatchGroup) Range() (int, int) {
|
||||
func (g RegexMatchGroup) Length() int {
|
||||
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