diff --git a/core/mapper/exprmapper/function/string/contains/contains.go b/core/mapper/exprmapper/function/string/contains/contains.go new file mode 100644 index 0000000..f33c8c4 --- /dev/null +++ b/core/mapper/exprmapper/function/string/contains/contains.go @@ -0,0 +1,30 @@ +package contains + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("contains-function") + +type Contains struct { +} + +func init() { + function.Registry(&Contains{}) +} + +func (co *Contains) GetName() string { + return "contains" +} + +func (co *Contains) GetCategory() string { + return "string" +} + +func (co *Contains) Eval(s string, substr string) bool { + // Documentation to function: https://golang.org/pkg/strings/#Contains + log.Debugf("Calling function contains with parameters [s = %s, substr = %s]", s, substr) + return strings.Contains(s, substr); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/contains/contains_test.go b/core/mapper/exprmapper/function/string/contains/contains_test.go new file mode 100644 index 0000000..19b3f92 --- /dev/null +++ b/core/mapper/exprmapper/function/string/contains/contains_test.go @@ -0,0 +1,21 @@ +package contains + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var co = &Contains{} + +func TestContains(t *testing.T) { + + sub := co.Eval("Flogo is the most awesome project ever", "awesome") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "XXXXXXXX") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) + +} diff --git a/core/mapper/exprmapper/function/string/containsany/containsany.go b/core/mapper/exprmapper/function/string/containsany/containsany.go new file mode 100644 index 0000000..a6b7e94 --- /dev/null +++ b/core/mapper/exprmapper/function/string/containsany/containsany.go @@ -0,0 +1,30 @@ +package containsany + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("containsany-function") + +type Containsany struct { +} + +func init() { + function.Registry(&Containsany{}) +} + +func (co *Containsany) GetName() string { + return "containsany" +} + +func (co *Containsany) GetCategory() string { + return "string" +} + +func (co *Containsany) Eval(s string, chars string) bool { + // Documentation to function: https://golang.org/pkg/strings/#ContainsAny + log.Debugf("Calling function containsany with parameters [s = %s, chars = %s]", s, chars) + return strings.ContainsAny(s, chars); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/containsany/containsany_test.go b/core/mapper/exprmapper/function/string/containsany/containsany_test.go new file mode 100644 index 0000000..0f77785 --- /dev/null +++ b/core/mapper/exprmapper/function/string/containsany/containsany_test.go @@ -0,0 +1,28 @@ +package containsany + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var co = &Containsany{} + +func TestContainsany(t *testing.T) { + + sub := co.Eval("Flogo is the most awesome project ever", "o") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "i & z") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "z & go") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "z") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) +} diff --git a/core/mapper/exprmapper/function/string/count/count.go b/core/mapper/exprmapper/function/string/count/count.go new file mode 100644 index 0000000..eddba77 --- /dev/null +++ b/core/mapper/exprmapper/function/string/count/count.go @@ -0,0 +1,30 @@ +package count + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("count-function") + +type Count struct { +} + +func init() { + function.Registry(&Count{}) +} + +func (co *Count) GetName() string { + return "count" +} + +func (co *Count) GetCategory() string { + return "string" +} + +func (co *Count) Eval(s string, substr string) int { + // Documentation to function: https://golang.org/pkg/strings/#Count + log.Debugf("Calling function count with parameters [s = %s, substr = %s]", s, substr) + return strings.Count(s, substr); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/count/count_test.go b/core/mapper/exprmapper/function/string/count/count_test.go new file mode 100644 index 0000000..0e66d5e --- /dev/null +++ b/core/mapper/exprmapper/function/string/count/count_test.go @@ -0,0 +1,28 @@ +package count + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var co = &Count{} + +func TestCount(t *testing.T) { + + sub := co.Eval("Flogo is the most awesome project ever", "Flogo") + fmt.Printf("Result [%d] should be equal to: 1\n", sub) + assert.Equal(t, 1, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "flogo") + fmt.Printf("Result [%d] should be equal to: 0\n", sub) + assert.Equal(t, 0, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "XXXXXXXX") + fmt.Printf("Result [%d] should be equal to: 0\n", sub) + assert.Equal(t, 0, sub) + + sub = co.Eval("Flogo is the most awesome project ever", "o") + fmt.Printf("Result [%d] should be equal to: 5\n", sub) + assert.Equal(t, 5, sub) +} diff --git a/core/mapper/exprmapper/function/string/hasprefix/hasprefix.go b/core/mapper/exprmapper/function/string/hasprefix/hasprefix.go new file mode 100644 index 0000000..7001061 --- /dev/null +++ b/core/mapper/exprmapper/function/string/hasprefix/hasprefix.go @@ -0,0 +1,30 @@ +package hasprefix + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("hasprefix-function") + +type Hasprefix struct { +} + +func init() { + function.Registry(&Hasprefix{}) +} + +func (ha *Hasprefix) GetName() string { + return "hasprefix" +} + +func (ha *Hasprefix) GetCategory() string { + return "string" +} + +func (ha *Hasprefix) Eval(s string, prefix string) bool { + // Documentation to function: https://golang.org/pkg/strings/#HasPrefix + log.Debugf("Calling function hasprefix with parameters [s = %s, prefix = %s]", s, prefix) + return strings.HasPrefix(s, prefix); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/hasprefix/hasprefix_test.go b/core/mapper/exprmapper/function/string/hasprefix/hasprefix_test.go new file mode 100644 index 0000000..70c175e --- /dev/null +++ b/core/mapper/exprmapper/function/string/hasprefix/hasprefix_test.go @@ -0,0 +1,29 @@ +package hasprefix + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var ha = &Hasprefix{} + +func TestHasprefix(t *testing.T) { + + sub := ha.Eval("Flogo is the most awesome project ever", "Flogo") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "flogo") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "Any other thing") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + +} diff --git a/core/mapper/exprmapper/function/string/hassuffix/hassuffix.go b/core/mapper/exprmapper/function/string/hassuffix/hassuffix.go new file mode 100644 index 0000000..9ed0465 --- /dev/null +++ b/core/mapper/exprmapper/function/string/hassuffix/hassuffix.go @@ -0,0 +1,30 @@ +package hassuffix + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("hassuffix-function") + +type Hassuffix struct { +} + +func init() { + function.Registry(&Hassuffix{}) +} + +func (ha *Hassuffix) GetName() string { + return "hassuffix" +} + +func (ha *Hassuffix) GetCategory() string { + return "string" +} + +func (ha *Hassuffix) Eval(s string, suffix string) bool { + // Documentation to function: https://golang.org/pkg/strings/#HasSuffix + log.Debugf("Calling function hassuffix with parameters [s = %s, suffix = %s]", s, suffix) + return strings.HasSuffix(s, suffix); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/hassuffix/hassuffix_test.go b/core/mapper/exprmapper/function/string/hassuffix/hassuffix_test.go new file mode 100644 index 0000000..04680bc --- /dev/null +++ b/core/mapper/exprmapper/function/string/hassuffix/hassuffix_test.go @@ -0,0 +1,29 @@ +package hassuffix + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var ha = &Hassuffix{} + +func TestHassuffix(t *testing.T) { + + sub := ha.Eval("Flogo is the most awesome project ever", "ever") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "EVER") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "XXXX") + fmt.Printf("Result [%t] should be equal to: false\n", sub) + assert.Equal(t, false, sub) + + sub = ha.Eval("Flogo is the most awesome project ever", "") + fmt.Printf("Result [%t] should be equal to: true\n", sub) + assert.Equal(t, true, sub) + +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/index/index.go b/core/mapper/exprmapper/function/string/index/index.go new file mode 100644 index 0000000..8960e09 --- /dev/null +++ b/core/mapper/exprmapper/function/string/index/index.go @@ -0,0 +1,30 @@ +package index + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("index-function") + +type Index struct { +} + +func init() { + function.Registry(&Index{}) +} + +func (in *Index) GetName() string { + return "index" +} + +func (in *Index) GetCategory() string { + return "string" +} + +func (in *Index) Eval(s string, substr string) int { + // Documentation to function: https://golang.org/pkg/strings/#Index + log.Debugf("Calling function index with parameters [s = %s, substr = %s]", s, substr) + return strings.Index(s, substr); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/index/index_test.go b/core/mapper/exprmapper/function/string/index/index_test.go new file mode 100644 index 0000000..e903312 --- /dev/null +++ b/core/mapper/exprmapper/function/string/index/index_test.go @@ -0,0 +1,25 @@ +package index + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var in = &Index{} + +func TestIndex(t *testing.T) { + + sub := in.Eval("Flogo is the most awesome project ever", "Flogo") + fmt.Printf("Result [%d] should be equal to: 0\n", sub) + assert.Equal(t, 0, sub) + + sub = in.Eval("Flogo is the most awesome project ever", "flogo") + fmt.Printf("Result [%d] should be equal to: -1\n", sub) + assert.Equal(t, -1, sub) + + sub = in.Eval("Flogo is the most awesome project ever", "awesome") + fmt.Printf("Result [%d] should be equal to: 18\n", sub) + assert.Equal(t, 18, sub) + +} diff --git a/core/mapper/exprmapper/function/string/join/join.go b/core/mapper/exprmapper/function/string/join/join.go new file mode 100644 index 0000000..641804b --- /dev/null +++ b/core/mapper/exprmapper/function/string/join/join.go @@ -0,0 +1,30 @@ +package join + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("join-function") + +type Join struct { +} + +func init() { + function.Registry(&Join{}) +} + +func (jo *Join) GetName() string { + return "join" +} + +func (jo *Join) GetCategory() string { + return "string" +} + +func (jo *Join) Eval(a []string, sep string) string { + // Documentation to function: https://golang.org/pkg/strings/#Join + log.Debugf("Calling function join with parameters [a = %s, sep = %s]", a, sep) + return strings.Join(a, sep); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/join/join_test.go b/core/mapper/exprmapper/function/string/join/join_test.go new file mode 100644 index 0000000..5631709 --- /dev/null +++ b/core/mapper/exprmapper/function/string/join/join_test.go @@ -0,0 +1,22 @@ +package join + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var jo = &Join{} + +func TestJoin(t *testing.T) { + + words := []string{"Flogo","is","the","most","awesome","project","ever"} + sub := jo.Eval(words, " ") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project ever\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project ever", sub) + + sub = jo.Eval(words, ",") + fmt.Printf("Result [%s] should be equal to: \"Flogo,is,the,most,awesome,project,ever\"\n", sub) + assert.Equal(t, "Flogo,is,the,most,awesome,project,ever", sub) + +} diff --git a/core/mapper/exprmapper/function/string/lastindex/lastindex.go b/core/mapper/exprmapper/function/string/lastindex/lastindex.go new file mode 100644 index 0000000..37c4f3e --- /dev/null +++ b/core/mapper/exprmapper/function/string/lastindex/lastindex.go @@ -0,0 +1,30 @@ +package lastindex + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("lastindex-function") + +type Lastindex struct { +} + +func init() { + function.Registry(&Lastindex{}) +} + +func (la *Lastindex) GetName() string { + return "lastindex" +} + +func (la *Lastindex) GetCategory() string { + return "string" +} + +func (la *Lastindex) Eval(s string, substr string) int { + // Documentation to function: https://golang.org/pkg/strings/#LastIndex + log.Debugf("Calling function lastindex with parameters [s = %s, substr = %s]", s, substr) + return strings.LastIndex(s, substr); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/lastindex/lastindex_test.go b/core/mapper/exprmapper/function/string/lastindex/lastindex_test.go new file mode 100644 index 0000000..54c8f57 --- /dev/null +++ b/core/mapper/exprmapper/function/string/lastindex/lastindex_test.go @@ -0,0 +1,28 @@ +package lastindex + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var la = &Lastindex{} + +func TestLastindex(t *testing.T) { + + sub := la.Eval("Flogo is the most awesome project ever", "o") + fmt.Printf("Result [%d] should be equal to: 28\n", sub) + assert.Equal(t, 28, sub) + + sub = la.Eval("Flogo is the most awesome project ever", "x") + fmt.Printf("Result [%d] should be equal to: -1\n", sub) + assert.Equal(t, -1, sub) + + sub = la.Eval("Flogo is the most awesome project ever", "flogo") + fmt.Printf("Result [%d] should be equal to: -1\n", sub) + assert.Equal(t, -1, sub) + + sub = la.Eval("Flogo is the most awesome project ever", "Flogo") + fmt.Printf("Result [%d] should be equal to: 0\n", sub) + assert.Equal(t, 0, sub) +} diff --git a/core/mapper/exprmapper/function/string/repeat/repeat.go b/core/mapper/exprmapper/function/string/repeat/repeat.go new file mode 100644 index 0000000..ef408cb --- /dev/null +++ b/core/mapper/exprmapper/function/string/repeat/repeat.go @@ -0,0 +1,30 @@ +package repeat + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("repeat-function") + +type Repeat struct { +} + +func init() { + function.Registry(&Repeat{}) +} + +func (re *Repeat) GetName() string { + return "repeat" +} + +func (re *Repeat) GetCategory() string { + return "string" +} + +func (re *Repeat) Eval(s string, count int) string { + // Documentation to function: https://golang.org/pkg/strings/#Repeat + log.Debugf("Calling function repeat with parameters [s = %s, count = %s]", s, count) + return strings.Repeat(s, count); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/repeat/repeat_test.go b/core/mapper/exprmapper/function/string/repeat/repeat_test.go new file mode 100644 index 0000000..3f8ed09 --- /dev/null +++ b/core/mapper/exprmapper/function/string/repeat/repeat_test.go @@ -0,0 +1,20 @@ +package repeat + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var re = &Repeat{} + +func TestRepeat(t *testing.T) { + + sub := "Flogo" + re.Eval("go", 5) + fmt.Printf("Result [%s] should be equal to: \"Flogogogogogogo\"\n", sub) + assert.Equal(t, "Flogogogogogogo", sub) + + sub = "Flogo is the most awesome project" + re.Eval(" ever", 2) + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project ever ever\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project ever ever", sub) +} diff --git a/core/mapper/exprmapper/function/string/replace/replace.go b/core/mapper/exprmapper/function/string/replace/replace.go new file mode 100644 index 0000000..5bc15b5 --- /dev/null +++ b/core/mapper/exprmapper/function/string/replace/replace.go @@ -0,0 +1,30 @@ +package replace + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("replace-function") + +type Replace struct { +} + +func init() { + function.Registry(&Replace{}) +} + +func (re *Replace) GetName() string { + return "replace" +} + +func (re *Replace) GetCategory() string { + return "string" +} + +func (re *Replace) Eval(s string, old string, new string, n int) string { + // Documentation to function: https://golang.org/pkg/strings/#Replace + log.Debugf("Calling function replace with parameters [s = %s, old = %s, new = %s, n = %s]", s, old, new, n) + return strings.Replace(s, old, new, n); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/replace/replace_test.go b/core/mapper/exprmapper/function/string/replace/replace_test.go new file mode 100644 index 0000000..8242771 --- /dev/null +++ b/core/mapper/exprmapper/function/string/replace/replace_test.go @@ -0,0 +1,25 @@ +package replace + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var re = &Replace{} + +func TestReplace(t *testing.T) { + + sub := re.Eval("Flogo is the most awesome project ever", "ever", "EVER", -1) + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER", sub) + + sub = re.Eval("Flogo is the most awesome project ever ever ever", "ever", "EVER", 2) + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER EVER ever\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER EVER ever", sub) + + sub = re.Eval("Flogo is the most awesome project ever", " ever", ". PERIOD", 0) + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project ever\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project ever", sub) + +} diff --git a/core/mapper/exprmapper/function/string/split/split.go b/core/mapper/exprmapper/function/string/split/split.go new file mode 100644 index 0000000..d7319c1 --- /dev/null +++ b/core/mapper/exprmapper/function/string/split/split.go @@ -0,0 +1,30 @@ +package split + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("split-function") + +type Split struct { +} + +func init() { + function.Registry(&Split{}) +} + +func (sp *Split) GetName() string { + return "split" +} + +func (sp *Split) GetCategory() string { + return "string" +} + +func (sp *Split) Eval(s string, sep string) []string { + // Documentation to function: https://golang.org/pkg/strings/#Split + log.Debugf("Calling function split with parameters [s = %s, sep = %s]", s, sep) + return strings.Split(s, sep); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/split/split_test.go b/core/mapper/exprmapper/function/string/split/split_test.go new file mode 100644 index 0000000..864e681 --- /dev/null +++ b/core/mapper/exprmapper/function/string/split/split_test.go @@ -0,0 +1,28 @@ +package split + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var sp = &Split{} + +func TestSplit(t *testing.T) { + + sub := sp.Eval("Flogo is the most awesome project ever", " ") + chk := []string{"Flogo","is","the","most","awesome","project","ever"} + fmt.Printf("Result [%s] should be equal to: \"[Flogo is the most awesome project ever]\" and size should be [7]\n", sub) + + assert.Equal(t, chk, sub) + assert.Equal(t, len(sub), 7) + + sub = sp.Eval("Flogo is the most awesome project ever", "-") + chk = []string{"Flogo is the most awesome project ever"} + fmt.Printf("Result [%s] should be equal to: \"[Flogo is the most awesome project ever]\" and size should be [1]\"\n", sub) + + assert.Equal(t, chk, sub) + assert.Equal(t, len(sub), 1) + + +} diff --git a/core/mapper/exprmapper/function/string/title/title.go b/core/mapper/exprmapper/function/string/title/title.go new file mode 100644 index 0000000..2b69876 --- /dev/null +++ b/core/mapper/exprmapper/function/string/title/title.go @@ -0,0 +1,30 @@ +package title + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("title-function") + +type Title struct { +} + +func init() { + function.Registry(&Title{}) +} + +func (ti *Title) GetName() string { + return "title" +} + +func (ti *Title) GetCategory() string { + return "string" +} + +func (ti *Title) Eval(s string) string { + // Documentation to function: https://golang.org/pkg/strings/#Title + log.Debugf("Calling function title with parameters [s = %s]", s) + return strings.Title(s); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/title/title_test.go b/core/mapper/exprmapper/function/string/title/title_test.go new file mode 100644 index 0000000..7f599a0 --- /dev/null +++ b/core/mapper/exprmapper/function/string/title/title_test.go @@ -0,0 +1,17 @@ +package title + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var ti = &Title{} + +func TestTitle(t *testing.T) { + + sub := ti.Eval("Flogo is the most awesome project ever") + fmt.Printf("Result [%s] should be equal to: \"Flogo Is The Most Awesome Project Ever\"\n", sub) + assert.Equal(t, "Flogo Is The Most Awesome Project Ever", sub) + +} diff --git a/core/mapper/exprmapper/function/string/tolower/tolower.go b/core/mapper/exprmapper/function/string/tolower/tolower.go new file mode 100644 index 0000000..788877e --- /dev/null +++ b/core/mapper/exprmapper/function/string/tolower/tolower.go @@ -0,0 +1,30 @@ +package tolower + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("tolower-function") + +type Tolower struct { +} + +func init() { + function.Registry(&Tolower{}) +} + +func (to *Tolower) GetName() string { + return "tolower" +} + +func (to *Tolower) GetCategory() string { + return "string" +} + +func (to *Tolower) Eval(s string) string { + // Documentation to function: https://golang.org/pkg/strings/#ToLower + log.Debugf("Calling function tolower with parameters [s = %s]", s) + return strings.ToLower(s); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/tolower/tolower_test.go b/core/mapper/exprmapper/function/string/tolower/tolower_test.go new file mode 100644 index 0000000..c4b506b --- /dev/null +++ b/core/mapper/exprmapper/function/string/tolower/tolower_test.go @@ -0,0 +1,16 @@ +package tolower + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var to = &Tolower{} + +func TestTolower(t *testing.T) { + + sub := to.Eval("Flogo is the most awesome project EVER") + fmt.Printf("Result [%s] should be equal to: \"flogo is the most awesome project ever\"\n", sub) + assert.Equal(t, "flogo is the most awesome project ever", sub) +} diff --git a/core/mapper/exprmapper/function/string/toupper/toupper.go b/core/mapper/exprmapper/function/string/toupper/toupper.go new file mode 100644 index 0000000..a245b38 --- /dev/null +++ b/core/mapper/exprmapper/function/string/toupper/toupper.go @@ -0,0 +1,30 @@ +package toupper + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("toupper-function") + +type Toupper struct { +} + +func init() { + function.Registry(&Toupper{}) +} + +func (to *Toupper) GetName() string { + return "toupper" +} + +func (to *Toupper) GetCategory() string { + return "string" +} + +func (to *Toupper) Eval(s string) string { + // Documentation to function: https://golang.org/pkg/strings/#ToUpper + log.Debugf("Calling function toupper with parameters [s = %s]", s) + return strings.ToUpper(s); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/toupper/toupper_test.go b/core/mapper/exprmapper/function/string/toupper/toupper_test.go new file mode 100644 index 0000000..af28fe1 --- /dev/null +++ b/core/mapper/exprmapper/function/string/toupper/toupper_test.go @@ -0,0 +1,16 @@ +package toupper + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var to = &Toupper{} + +func TestToupper(t *testing.T) { + + sub := to.Eval("Flogo is the most awesome project EVER") + fmt.Printf("Result [%s] should be equal to: \"FLOGO IS THE MOST AWESOME PROJECT EVER\"\n", sub) + assert.Equal(t, "FLOGO IS THE MOST AWESOME PROJECT EVER", sub) +} diff --git a/core/mapper/exprmapper/function/string/trim/trim.go b/core/mapper/exprmapper/function/string/trim/trim.go new file mode 100644 index 0000000..b50e0cd --- /dev/null +++ b/core/mapper/exprmapper/function/string/trim/trim.go @@ -0,0 +1,30 @@ +package trim + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trim-function") + +type Trim struct { +} + +func init() { + function.Registry(&Trim{}) +} + +func (tr *Trim) GetName() string { + return "trim" +} + +func (tr *Trim) GetCategory() string { + return "string" +} + +func (tr *Trim) Eval(s string, cutset string) string { + // Documentation to function: https://golang.org/pkg/strings/#Trim + log.Debugf("Calling function trim with parameters [s = %s, cutset = %s]", s, cutset) + return strings.Trim(s, cutset); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trim/trim_test.go b/core/mapper/exprmapper/function/string/trim/trim_test.go new file mode 100644 index 0000000..ae0c3cd --- /dev/null +++ b/core/mapper/exprmapper/function/string/trim/trim_test.go @@ -0,0 +1,24 @@ +package trim + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trim{} + +func TestTrim(t *testing.T) { + + sub := tr.Eval("Flogo is the most awesome project EVER...", ".") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "F.") + fmt.Printf("Result [%s] should be equal to: \"logo is the most awesome project EVER\"\n", sub) + assert.Equal(t, "logo is the most awesome project EVER", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "F.l") + fmt.Printf("Result [%s] should be equal to: \"ogo is the most awesome project EVER\"\n", sub) + assert.Equal(t, "ogo is the most awesome project EVER", sub) +} diff --git a/core/mapper/exprmapper/function/string/trimleft/trimleft.go b/core/mapper/exprmapper/function/string/trimleft/trimleft.go new file mode 100644 index 0000000..afaf2a0 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimleft/trimleft.go @@ -0,0 +1,30 @@ +package trimleft + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trimleft-function") + +type Trimleft struct { +} + +func init() { + function.Registry(&Trimleft{}) +} + +func (tr *Trimleft) GetName() string { + return "trimleft" +} + +func (tr *Trimleft) GetCategory() string { + return "string" +} + +func (tr *Trimleft) Eval(s string, cutset string) string { + // Documentation to function: https://golang.org/pkg/strings/#TrimLeft + log.Debugf("Calling function trimleft with parameters [s = %s, cutset = %s]", s, cutset) + return strings.TrimLeft(s, cutset); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trimleft/trimleft_test.go b/core/mapper/exprmapper/function/string/trimleft/trimleft_test.go new file mode 100644 index 0000000..37a6356 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimleft/trimleft_test.go @@ -0,0 +1,24 @@ +package trimleft + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trimleft{} + +func TestTrimleft(t *testing.T) { + + sub := tr.Eval("Flogo is the most awesome project EVER...", ".") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER...", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "F.") + fmt.Printf("Result [%s] should be equal to: \"logo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "logo is the most awesome project EVER...", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "F.l") + fmt.Printf("Result [%s] should be equal to: \"ogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "ogo is the most awesome project EVER...", sub) +} diff --git a/core/mapper/exprmapper/function/string/trimprefix/trimprefix.go b/core/mapper/exprmapper/function/string/trimprefix/trimprefix.go new file mode 100644 index 0000000..cd90ffd --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimprefix/trimprefix.go @@ -0,0 +1,30 @@ +package trimprefix + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trimprefix-function") + +type Trimprefix struct { +} + +func init() { + function.Registry(&Trimprefix{}) +} + +func (tr *Trimprefix) GetName() string { + return "trimprefix" +} + +func (tr *Trimprefix) GetCategory() string { + return "string" +} + +func (tr *Trimprefix) Eval(s string, prefix string) string { + // Documentation to function: https://golang.org/pkg/strings/#TrimPrefix + log.Debugf("Calling function trimprefix with parameters [s = %s, prefix = %s]", s, prefix) + return strings.TrimPrefix(s, prefix); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trimprefix/trimprefix_test.go b/core/mapper/exprmapper/function/string/trimprefix/trimprefix_test.go new file mode 100644 index 0000000..f4592eb --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimprefix/trimprefix_test.go @@ -0,0 +1,21 @@ +package trimprefix + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trimprefix{} + +func TestTrimprefix(t *testing.T) { + + sub := tr.Eval("TIBCO Flogo is the most awesome project EVER...", "TIBCO ") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER...", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "TIBCO") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER...", sub) + +} diff --git a/core/mapper/exprmapper/function/string/trimright/trimright.go b/core/mapper/exprmapper/function/string/trimright/trimright.go new file mode 100644 index 0000000..6b227c7 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimright/trimright.go @@ -0,0 +1,30 @@ +package trimright + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trimright-function") + +type Trimright struct { +} + +func init() { + function.Registry(&Trimright{}) +} + +func (tr *Trimright) GetName() string { + return "trimright" +} + +func (tr *Trimright) GetCategory() string { + return "string" +} + +func (tr *Trimright) Eval(s string, cutset string) string { + // Documentation to function: https://golang.org/pkg/strings/#TrimRight + log.Debugf("Calling function trimright with parameters [s = %s, cutset = %s]", s, cutset) + return strings.TrimRight(s, cutset); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trimright/trimright_test.go b/core/mapper/exprmapper/function/string/trimright/trimright_test.go new file mode 100644 index 0000000..abe8ef1 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimright/trimright_test.go @@ -0,0 +1,24 @@ +package trimright + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trimright{} + +func TestTrimright(t *testing.T) { + + sub := tr.Eval("TIBCO Flogo is the most awesome project EVER...", "TIBCO ") + fmt.Printf("Result [%s] should be equal to: \"TIBCO Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "TIBCO Flogo is the most awesome project EVER...", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", " EVER...") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "EVER") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER...", sub) +} diff --git a/core/mapper/exprmapper/function/string/trimspace/trimspace.go b/core/mapper/exprmapper/function/string/trimspace/trimspace.go new file mode 100644 index 0000000..7027d78 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimspace/trimspace.go @@ -0,0 +1,30 @@ +package trimspace + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trimspace-function") + +type Trimspace struct { +} + +func init() { + function.Registry(&Trimspace{}) +} + +func (tr *Trimspace) GetName() string { + return "trimspace" +} + +func (tr *Trimspace) GetCategory() string { + return "string" +} + +func (tr *Trimspace) Eval(s string) string { + // Documentation to function: https://golang.org/pkg/strings/#TrimSpace + log.Debugf("Calling function trimspace with parameters [s = %s]", s) + return strings.TrimSpace(s); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trimspace/trimspace_test.go b/core/mapper/exprmapper/function/string/trimspace/trimspace_test.go new file mode 100644 index 0000000..94f6d0f --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimspace/trimspace_test.go @@ -0,0 +1,20 @@ +package trimspace + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trimspace{} + +func TestTrimspace(t *testing.T) { + + sub := tr.Eval(" TIBCO Flogo is the most awesome project EVER... ") + fmt.Printf("Result [%s] should be equal to: \"TIBCO Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "TIBCO Flogo is the most awesome project EVER...", sub) + + sub = tr.Eval("TIBCO Flogo is the most awesome project EVER...") + fmt.Printf("Result [%s] should be equal to: \"TIBCO Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "TIBCO Flogo is the most awesome project EVER...", sub) +} diff --git a/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix.go b/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix.go new file mode 100644 index 0000000..465f601 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix.go @@ -0,0 +1,30 @@ +package trimsuffix + +import ( + "github.com/TIBCOSoftware/flogo-lib/core/mapper/exprmapper/expression/function" + "github.com/TIBCOSoftware/flogo-lib/logger" + "strings" +) + +var log = logger.GetLogger("trimsuffix-function") + +type Trimsuffix struct { +} + +func init() { + function.Registry(&Trimsuffix{}) +} + +func (tr *Trimsuffix) GetName() string { + return "trimsuffix" +} + +func (tr *Trimsuffix) GetCategory() string { + return "string" +} + +func (tr *Trimsuffix) Eval(s string, suffix string) string { + // Documentation to function: https://golang.org/pkg/strings/#TrimSuffix + log.Debugf("Calling function trimsuffix with parameters [s = %s, suffix = %s]", s, suffix) + return strings.TrimSuffix(s, suffix); +} \ No newline at end of file diff --git a/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix_test.go b/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix_test.go new file mode 100644 index 0000000..0229a90 --- /dev/null +++ b/core/mapper/exprmapper/function/string/trimsuffix/trimsuffix_test.go @@ -0,0 +1,24 @@ +package trimsuffix + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "testing" +) + +var tr = &Trimsuffix{} + +func TestTrimsuffix(t *testing.T) { + + sub := tr.Eval("TIBCO Flogo is the most awesome project EVER...", "TIBCO ") + fmt.Printf("Result [%s] should be equal to: \"TIBCO Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "TIBCO Flogo is the most awesome project EVER...", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", " EVER...") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project", sub) + + sub = tr.Eval("Flogo is the most awesome project EVER...", "") + fmt.Printf("Result [%s] should be equal to: \"Flogo is the most awesome project EVER...\"\n", sub) + assert.Equal(t, "Flogo is the most awesome project EVER...", sub) +}