Skip to content

Commit 56274eb

Browse files
committed
filename: don't coerce
1 parent ebabf90 commit 56274eb

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

+stdlib/filename.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515
switch backend
1616
case 'fileparts'
1717
[~, f, ext] = fileparts(p);
18-
f = f + ext;
18+
f = append(f, ext);
1919
% the pattern backend is a litle slower than regexp. Commented out for < R2020b compatibility
2020
% case 'pattern'
2121
% f = extractAfter(p, asManyOfPattern(wildcardPattern + ("/" | filesep)));
2222
case 'regexp'
23-
f = regexp(p, ['[^/\' filesep ']*$'], 'match', 'once');
24-
if ismissing(f)
25-
f = "";
23+
i = regexp(p, ['[^/\' filesep ']*$'], 'once');
24+
if isempty(i)
25+
f = extractBefore(p, 1);
26+
else
27+
f = extractAfter(p, i-1);
2628
end
27-
otherwise, error('must be backend "pattern", "regexp" or "fileparts"')
29+
otherwise
30+
error('must be backend "regexp" or "fileparts"')
2831
end
2932

3033
end

test/TestFilename.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ function test_filename(tc, p, backend)
2222

2323
function p = init_p()
2424
p = {
25-
{'', ""}, ...
25+
{'', ''}, ...
2626
{"", ""}, ...
2727
{"Hi", "Hi"}, ...
2828
{"/a/b/c", "c"}, ...
29-
{'a/b/c.txt', "c.txt"}, ...
29+
{'a/b/c.txt', 'c.txt'}, ...
3030
{"a///b//c.txt.gz", "c.txt.gz"}, ...
3131
{"a/b/.hello", ".hello"}
3232
};

0 commit comments

Comments
 (0)