Skip to content

Commit

Permalink
Merge pull request #242 from refaktor/modwords
Browse files Browse the repository at this point in the history
adding trim\right, trim renamed to trim\spaces, trim\ to trim
  • Loading branch information
refaktor committed Jun 16, 2024
2 parents 961a1f2 + 9dd18d8 commit 95be5e6
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions evaldo/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -5630,7 +5630,7 @@ var builtins = map[string]*env.Builtin{
},
},

"trim": {
"trim\\space": {
Argsn: 1,
Doc: "Trims the String of spacing characters.",
Pure: true,
Expand All @@ -5643,7 +5643,7 @@ var builtins = map[string]*env.Builtin{
}
},
},
"trim\\": {
"trim": {
Argsn: 2,
Doc: "Trims the String of specific characters.",
Pure: true,
Expand All @@ -5661,6 +5661,42 @@ var builtins = map[string]*env.Builtin{
}
},
},
"trim\\right": {
Argsn: 2,
Doc: "Trims the String of specific characters.",
Pure: true,
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch s1 := arg0.(type) {
case env.String:
switch s2 := arg1.(type) {
case env.String:
return *env.NewString(strings.TrimRight(s1.Value, s2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.StringType}, "trim\\")
}
default:
return MakeArgError(ps, 1, []env.Type{env.StringType}, "trim\\")
}
},
},
"trim\\left": {
Argsn: 2,
Doc: "Trims the String of specific characters.",
Pure: true,
Fn: func(ps *env.ProgramState, arg0 env.Object, arg1 env.Object, arg2 env.Object, arg3 env.Object, arg4 env.Object) env.Object {
switch s1 := arg0.(type) {
case env.String:
switch s2 := arg1.(type) {
case env.String:
return *env.NewString(strings.TrimLeft(s1.Value, s2.Value))
default:
return MakeArgError(ps, 2, []env.Type{env.StringType}, "trim\\")
}
default:
return MakeArgError(ps, 1, []env.Type{env.StringType}, "trim\\")
}
},
},

"replace": {
Argsn: 3,
Expand Down

0 comments on commit 95be5e6

Please sign in to comment.