/
string_endswith.go
59 lines (54 loc) · 1.25 KB
/
string_endswith.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package elem
import (
"strings"
"github.com/Bitspark/slang/pkg/core"
"github.com/google/uuid"
)
var stringEndswithCfg = &builtinConfig{
safe: true,
blueprint: core.Blueprint{
Id: uuid.MustParse("db8b1677-baaf-4072-8047-0359cd68be9e"),
Meta: core.BlueprintMetaDef{
Name: "ends with",
ShortDescription: "tells if a string ends with another string",
Icon: "hand-point-right",
Tags: []string{"string"},
DocURL: "https://bitspark.de/slang/docs/operator/ends-with",
},
ServiceDefs: map[string]*core.ServiceDef{
core.MAIN_SERVICE: {
In: core.TypeDef{
Type: "map",
Map: map[string]*core.TypeDef{
"str": {
Type: "string",
},
"substr": {
Type: "string",
},
},
},
Out: core.TypeDef{
Type: "boolean",
},
},
},
DelegateDefs: map[string]*core.DelegateDef{},
},
opFunc: func(op *core.Operator) {
in := op.Main().In()
out := op.Main().Out()
for !op.CheckStop() {
i := in.Pull()
if core.IsMarker(i) {
out.Push(i)
continue
}
dataIn := i.(map[string]interface{})
str := dataIn["str"].(string)
subStr := dataIn["substr"].(string)
dataOut := strings.HasSuffix(str, subStr)
out.Push(dataOut)
}
},
}