Skip to content

Commit b30670b

Browse files
committed
parent: don't coerceE
1 parent 072b7d6 commit b30670b

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

+stdlib/drop_slash.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
%% DROP_SLASH drop repeated and trailing slash
2-
%
32

43
function d = drop_slash(filepath)
5-
arguments
6-
filepath string
7-
end
84

95
s = stdlib.posix(filepath);
106

117
% drop repeated slashes inside string
128
d = regexprep(s, '/+', '/');
139

1410
% drop all trailing slashes
15-
i = ~strcmp(d, '/') & ~strcmp(d, stdlib.root(s));
16-
17-
d(i) = regexprep(d(i), '/$', '');
11+
if ~strcmp(d, '/') && ~strcmp(d, stdlib.root(s));
12+
d = regexprep(d, '/$', '');
13+
end
1814

1915
end

+stdlib/parent.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
% stdlib.parent("a/b/c/") == "a/b"
1010

1111
function p = parent(file)
12-
arguments
13-
file (1,1) string
14-
end
1512

1613
p = fileparts(stdlib.drop_slash(file));
1714

1815
if stdlib.strempty(p)
19-
p = ".";
16+
p = '.';
17+
if isstring(file)
18+
p = string(p);
19+
end
2020
elseif ispc() && p == stdlib.root_name(file)
21-
p = p + "/";
21+
p = append(p, '/');
2222
end
2323

2424
end

test/TestParent.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function test_parent(tc, p)
2626
{".", "."}, ...
2727
{"..", "."}, ...
2828
{"../..", ".."}, ...
29-
{"a/", "."}, ...
29+
{'a/', '.'}, ...
3030
{"a/b", "a"}, ...
3131
{"ab/.parent", "ab"}, ...
3232
{"ab/.parent.txt", "ab"}, ...
@@ -41,7 +41,7 @@ function test_parent(tc, p)
4141
p{end+1} = {"c:", "c:/"};
4242
end
4343

44-
p{end+1} = {'a/b/', "a"};
45-
p{end+1} = {'a//b', "a"};
44+
p{end+1} = {'a/b/', 'a'};
45+
p{end+1} = {'a//b', 'a'};
4646

4747
end

0 commit comments

Comments
 (0)