skx / evalfilter

A bytecode-based virtual machine to implement scripting/filtering support in your golang project.
GNU General Public License v2.0
117 stars 12 forks source link

We can't search/replace.. #180

Closed skx closed 2 years ago

skx commented 2 years ago

I looked at using evalfilter to embed some scripting in my utility-project, but one omission killed that:

Specifically I wanted to turn "foo bar baz.pdf" into "foo_bar_baz.pdf" (i.e. change spaces to underscores).

You could turn a string into an array with split, but you're missing the join to turn the array back into a string:

  name = join( split( name, " " ), "_" )

Adding join is a no-brainer, to allow this problem to be solved indirectly. Of course we should also support replace to allow:

name = replace( name, / /, "_" )

That would do regular expression replacement. I'm not sure if that is better than a character replacement, but i suspect it is..

skx commented 2 years ago

However both failed the linter as my attempt to compare whether a floating-point number was secretly an integer failed. This is an update from golangci-lint and will be resolved shortly.