Skip to content

Commit

Permalink
added indexOf
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalcek committed Dec 15, 2023
1 parent be3b12e commit a90a7e5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func templateFunctions() template.FuncMap {
"trim": trim,
"trimAll": trimAll,
"trimSuffix": trimSuffix,
"indexOf": indexOf,
"trimPrefix": trimPrefix,
"atoi": atoi,
"toBool": toBool,
Expand Down Expand Up @@ -345,7 +346,13 @@ func trimPrefix(a, b string) string { return strings.TrimPrefix(a, b) }
// trimSuffix - {{trimSuffix "!Hello World!" "!"}} - returns "!HelloWorld"
func trimSuffix(a, b string) string { return strings.TrimSuffix(a, b) }

// - atoi {{atoi "42"}} - string to int
// indexOf {{indexOf "abcd", "bc"}} -> 1
// TODO: add to tests and documentation
func indexOf(a, b string) int {
return strings.Index(a, b)
}

// atoi {{atoi "42"}} - string to int
func atoi(a string) int { i, _ := strconv.Atoi(a); return i }

func toBool(v interface{}) bool {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21.4
require (
github.com/clbanning/mxj/v2 v2.5.5
github.com/google/uuid v1.3.0
github.com/mmalcek/mt940 v0.0.3
github.com/mmalcek/mt940 v0.0.4
github.com/shopspring/decimal v1.3.1
github.com/spf13/cast v1.4.1
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mmalcek/mt940 v0.0.3 h1:yBFqyIaghCERkAc3oeAUluhTjnApCN8flXOvJ1JTBkg=
github.com/mmalcek/mt940 v0.0.3/go.mod h1:DKDmNW/6NI04F2d7G77auppzg1Ylis5m7Whrq3fR8x0=
github.com/mmalcek/mt940 v0.0.4 h1:1npu4EFifUurohHwB4puA/DvI2X92kSE8crP+zvAZlg=
github.com/mmalcek/mt940 v0.0.4/go.mod h1:DKDmNW/6NI04F2d7G77auppzg1Ylis5m7Whrq3fR8x0=
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit a90a7e5

Please sign in to comment.