Last active
August 29, 2015 13:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
/**! | |
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