Skip to content

Commit 35b459e

Browse files
committed
filename: validate input
1 parent eadb0b6 commit 35b459e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

+stdlib/filename.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,17 @@
77

88
function f = filename(p, method)
99
arguments
10-
p
11-
method = 'pattern'
10+
p string
11+
method {mustBeMember(method, {'pattern', 'regexp'})} = 'pattern'
1212
end
1313

1414
% the pattern method is a few percent faster than regexp
1515
switch method
16-
case 'pattern', f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
16+
case 'pattern'
17+
f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
1718
case 'regexp'
1819
f = regexp(p, ['[^/\' filesep ']*$'], 'match', 'once');
19-
try %#ok<TRYNC>
20-
f(ismissing(f)) = "";
21-
end
22-
otherwise, error('unknown method %s', method)
20+
f(ismissing(f)) = "";
2321
end
2422

2523
end

0 commit comments

Comments
 (0)