Skip to content

Commit d8dec14

Browse files
committed
suffix: don't coerce
1 parent 184166b commit d8dec14

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

+stdlib/suffix.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
%% SUFFIX last suffix of filename
22

33
function s = suffix(p)
4-
arguments
5-
p string
6-
end
74

85
[~, n, s] = fileparts(p);
96

10-
i = stdlib.strempty(n);
11-
s(i) = n(i);
7+
if stdlib.strempty(n)
8+
s = n;
9+
end
1210

1311
end

test/TestSuffix.m

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,24 @@
88
{"a/a.b/hi.txt", ".txt"}, ...
99
{"a/a.b/matlab", ""}, ...
1010
{"a/b/c.txt.gz", ".gz"}, ...
11-
{'.stat', ""}, ...
12-
{'a/.stat', ""}, ...
13-
{'.stat.txt', ".txt"}}
11+
{'.stat', ''}, ...
12+
{'a/.stat', ''}, ...
13+
{'.stat.txt', '.txt'}}
1414
end
1515

1616

1717
methods (Test, TestTags={'R2019b'})
18+
1819
function test_suffix(tc, p)
19-
tc.verifyEqual(stdlib.suffix(p{1}), p{2})
20+
r = stdlib.suffix(p{1});
21+
if isempty(p{2})
22+
tc.verifyEmpty(r)
23+
else
24+
tc.verifyEqual(r, p{2})
2025
end
2126
end
2227

23-
methods (Test, TestTags={'R2020b'})
24-
25-
function test_suffix_array(tc)
26-
tc.assumeFalse(stdlib.matlabOlderThan('R2020b'))
27-
in = ["", ".txt", "a/b/c.txt", "a/b/c.txt.gz", "a/b/c"];
28-
exp = ["", "", ".txt", ".gz", ""];
29-
out = stdlib.suffix(in);
30-
tc.verifyEqual(out, exp)
3128
end
3229

33-
end
3430

3531
end

0 commit comments

Comments
 (0)