Skip to content

Commit 0ee7271

Browse files
committed
stem: handle corner case of leading dot filename
1 parent f824994 commit 0ee7271

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

+stdlib/stem.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
%% STEM filename without directory or suffix
22

3-
function p = stem(p)
3+
function st = stem(p)
44
% arguments
55
% p (1,1) string
66
% end
77

8-
[~, p] = fileparts(p);
8+
[~, n, s] = fileparts(p);
9+
10+
if stdlib.len(n)
11+
st = n;
12+
else
13+
st = s;
14+
end
915

1016
end
1117

1218
%!assert(stem('/a/b.c'), 'b')
19+
%!assert(stem("a/b/.c"), ".c")

+stdlib/with_suffix.m

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,7 @@
1616
s = stdlib.stem(p);
1717

1818
if stdlib.len(s) == 0
19-
if stdlib.len(stdlib.filename(p))
20-
if ischar(r)
21-
f = strcat(p, suffix);
22-
else
23-
f = p + suffix;
24-
end
25-
else
26-
f = stdlib.join(p, suffix, false);
27-
end
19+
f = stdlib.join(p, suffix, false);
2820
return
2921
end
3022

test/TestFilePure.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
{"a/b/c.txt.gz", "c.txt.gz"}
1414
};
1515

16-
p_stem ={{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, {"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}}
16+
p_stem ={{"/a/b/c", "c"}, {"/a/b/c/", ""}, {"a/b/c/", ""}, ...
17+
{"a/b/c.txt", "c"}, {"a/b/c.txt.gz", "c.txt"}, ...
18+
{"a/b/.c", ".c"}}
1719

1820
p_join = {{"", "", ""}, ...
1921
{"a", "", "a"}, ...

0 commit comments

Comments
 (0)