NASAL: fix new truncateAt method to handle nil ptr errors during execution
This commit is contained in:
parent
79dc657170
commit
4e0483c9e8
1 changed files with 8 additions and 3 deletions
|
@ -51,9 +51,14 @@ var trim = func(s, lr = 0, istrim = nil) {
|
|||
# string.truncateAt("file.xml", ".txt"); # "file.xml" -> "file.xml"
|
||||
#
|
||||
var truncateAt = func(src, match){
|
||||
var pos = find(match,src);
|
||||
if (pos>=0)
|
||||
return substr(src,0,pos);
|
||||
var rv = nil;
|
||||
call(func {
|
||||
if (src != nil and match !=nil) {
|
||||
var pos = find(match,src);
|
||||
if (pos>=0)
|
||||
src=substr(src,0,pos);
|
||||
}
|
||||
}, nil, var err = []);
|
||||
return src;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue