Skip to content

Commit e718c98

Browse files
committed
suffix: vectorize
1 parent 3f497ab commit e718c98

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

+stdlib/suffix.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
function s = suffix(p)
44
arguments
5-
p {mustBeTextScalar}
5+
p string
66
end
77

8-
[~, ~, s] = fileparts(p);
8+
pat = textBoundary("start") + asManyOfPattern(wildcardPattern + ".", 1);
99

10-
end
10+
s = extractAfter(p, pat);
11+
12+
i = ~ismissing(s);
13+
s(~i) = "";
1114

12-
%!assert (suffix('/a/b.c'), '.c')
15+
s(i) = strcat('.', s(i));
16+
17+
end

test/TestSuffix.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
p = {{"", ""}, {"/a/b/c", ""}, ...
55
{"/a/b/c/", ""}, {"a/b/c.txt", ".txt"}, ...
66
{"a/b/c.txt.gz", ".gz"}, ...
7-
{'.stat', '.stat'}, ...
8-
{'.stat.txt', '.txt'}}
7+
{'.stat', ".stat"}, ...
8+
{'.stat.txt', ".txt"}}
99
end
1010

1111
methods (Test, TestTags="pure")

0 commit comments

Comments
 (0)