Skip to content

Commit 4a355b2

Browse files
committed
root: don't coerce type
1 parent a69e172 commit 4a355b2

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

+stdlib/root.m

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,23 @@
55

66
function r = root(p)
77
arguments
8-
p (1,1) string
8+
p {mustBeTextScalar}
99
end
1010

1111
r = stdlib.root_name(p);
1212

1313
if ~strlength(r)
14-
if strncmp(p, "/", 1)
15-
r = "/";
14+
if strncmp(p, '/', 1)
15+
r = '/';
1616
end
17-
18-
return
17+
elseif ~(ispc && strcmp(r, p))
18+
r = strcat(r, '/');
1919
end
2020

21-
if ispc && strcmp(r, p)
22-
return
21+
if isstring(p)
22+
r = string(r);
2323
end
2424

25-
r = strcat(r, "/");
26-
2725
end
2826

2927
%!assert(root(''), '')

test/TestRoot.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function test_root(tc, p)
1818
p = {{"", ""}, ...
1919
{"a/b", ""}, ...
2020
{"./a/b", ""}, ...
21-
{"/etc", "/"}, ...
21+
{'/etc', '/'}, ...
2222
{"c:", ""}, ...
2323
{"c:/etc", ""}};
2424

0 commit comments

Comments
 (0)