Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/9957770 to your computer and use it in GitHub Desktop.
Save jolle-c/9957770 to your computer and use it in GitHub Desktop.
Adding an optional param to string -> trim so that it works on any character.
[
/**!
Lasso 9
Adding an optional param to string -> trim so that it works on any character.
Example
local(mypath = response_filepath)
#mypath -> trim('/')
#mypath
local(mystring = 'xxxräksmörgåsxx')
#mystring -> trim('x')
#mystring
Can also use an array
local(mystring = 'xzyräksmörgåsxyz')
#mystring -> trim(array('x','y','z'))
#mystring
**/
define string -> trim(trim::string) => {
.removeleading(#trim) & .removetrailing(#trim)
}
// There is no string -> removetrailing(regexp) in the distro but there is a removeleading(regexp)
// This is a quick and dirty fix for that
define string -> removetrailing(find::regexp)=> {
{
.reverse
#find->input = self
if(!#find->matchesStart) => {
.reverse
return
}
.remove(1, #find->matchPosition->second)
.reverse
currentCapture->restart
}()
}
define string -> trim(trim::array) => {
if(#trim >> `|`) => {
#trim -> removeall(`|`)
#trim -> insert(`\|`)
}
local(remove = `(` + #trim -> join(`|`) + `)`)
.removeleading(regexp(#remove)) & .removetrailing(regexp(#remove))
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment