[lp_file_trimPath]
Description
Returns a sanitized path that will never specify from harddisk root.
Requires [lp_string_split]
Parameters
-path
string, required
The path to sanitize.
Sample Usage
'<pre>';
var:'paths' = (:
'/this/that ',
' /this/ that/ ',
'//this//../that//',
'///this/that/ ',
'c://somedir/ ',
' c:\\this\\that\\',
'/this/somefile.txt',
'c://somedir/this/somefile.txt'
);
iterate: $paths, local:'path';
'"' #path '"';
'\t';
'"' (lp_file_trimpath:#path) '"';
'\r\n';
/iterate;
'</pre>';
Returns:
"/this/that " "/this/that"
" /this/ that/ " "/this/that/"
"//this//../that//" "/this/that/"
"///this/that/ " "/this/that/"
"c://somedir/ " "/somedir/"
" c:\this\that\" "/this/that/"
"/this/somefile.txt" "/this/somefile.txt"
"c://somedir/this/somefile.txt" "/somedir/this/somefile.txt"
Source Code
Click the "Download" button below to retrieve a copy of this tag,
including the complete documentation and sample usage shown
on this page. Place the downloaded ".inc" file in your
LassoStartup folder, restart Lasso, and you can begin using this
tag immediately.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[
define_tag:'lp_file_trimPath',
-description='Returns a sanitized path that will never specify from harddisk root.',
-priority='replace',
-required='path';
local:'newpath' = (string: #path);
#newpath->(replace:'\\','/');
if: #newpath->(contains:':');
#newpath = (lp_string_split: #newpath, ':', 2)->(get:2);
/if;
#newpath = (string_replaceregexp: #newpath, -find="[^a-z0-9\\/\\!\\@\\#\\$\\%\\^\\&\\(\\)\\{\\}\\-\\=\\_\\+\\~\\`\\;\\'\\,\\.]", -replace='', -ignorecase);
#newpath = (string_replaceregexp: #newpath, -find="\\.\\.+", -replace='..', -ignorecase);
#newpath = (string_replaceregexp: #newpath, -find="/+", -replace='/', -ignorecase);
return: #newpath;
]
Comments
none
Newest
Most Popular
Support tagSwap.net