Skip to content

Commit 8b16e66

Browse files
committed
native.parent: any size array
1 parent 055234d commit 8b16e66

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

+stdlib/+native/parent.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
function p = parent(pth)
2-
3-
f = fullfile(char(pth));
4-
if endsWith(f, {'/', filesep}) && ~strcmp(f, stdlib.root(f))
5-
f = f(1:end-1);
2+
arguments
3+
pth string
64
end
75

6+
f = fullfile(pth);
7+
8+
i = endsWith(f, ["/", filesep]) & ~strcmp(f, stdlib.root(f));
9+
10+
f(i) = extractBefore(f(i), strlength(f(i)));
11+
812
p = fileparts(f);
913

10-
if stdlib.strempty(p)
11-
p = '.';
12-
elseif ispc() && strcmp(p, stdlib.root_name(pth))
13-
p = strcat(p, filesep);
14-
end
14+
i = stdlib.strempty(p);
15+
p(i) = ".";
1516

16-
p = string(p);
17+
i = ispc() & strcmp(p(~i), stdlib.root_name(pth));
18+
p(i) = strcat(p(i), filesep);
1719

1820
end

+stdlib/parent.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
% stdlib.parent("a/b/c") == "a/b"
55
% stdlib.parent("a/b/c/") == "a/b"
66

7-
function p = parent(pth, backend)
7+
function par = parent(file, backend)
88
arguments
9-
pth {mustBeTextScalar}
10-
backend (1,:)string = ["java", "python", "native"]
9+
file string
10+
backend (1,:) string = ["java", "python", "native"]
1111
end
1212

13-
fun = hbackend(backend, "parent");
14-
15-
p = fun(pth);
13+
if isscalar(file)
14+
fun = hbackend(backend, "parent");
15+
par = fun(file);
16+
else
17+
par = stdlib.native.parent(file);
18+
end
1619

1720
end

0 commit comments

Comments
 (0)