Skip to content

Commit

Permalink
Update lagra.go
Browse files Browse the repository at this point in the history
  • Loading branch information
simplyYan authored Sep 18, 2023
1 parent 8242380 commit e08d186
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lagra.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,28 @@ func (ec *ErrorCollector) Handle() bool {
func (ec *ErrorCollector) Errors() []error {
return ec.errors
}

type StrSelect struct {
strMap map[string]string
}

func NewStrSelect() *StrSelect {
return &StrSelect{
strMap: make(map[string]string),
}
}

func (s *StrSelect) SetStr(strName, value string) {
s.strMap[strName] = value
}

func (s *StrSelect) SelectStr(strName, delimiter string) string {
if str, ok := s.strMap[strName]; ok {
startIdx := strings.Index(str, delimiter)
endIdx := strings.LastIndex(str, delimiter)
if startIdx != -1 && endIdx != -1 && startIdx < endIdx {
return str[startIdx+len(delimiter) : endIdx]
}
}
return ""
}

0 comments on commit e08d186

Please sign in to comment.