Skip to content

Commit 6cacd51

Browse files
committed
root_dir: simpler
1 parent d0d04c8 commit 6cacd51

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

+stdlib/root_dir.m

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@
1313
p {mustBeTextScalar}
1414
end
1515

16-
r = '';
17-
pc = char(p);
18-
19-
if startsWith(p, {'/', filesep})
20-
r = pc(1);
21-
elseif strlength(p) > 2 && ~strempty(stdlib.root_name(p))
22-
if ismember(pc(3), {'/', filesep})
23-
r = pc(3);
16+
matches = regexp(p, '^([/\\])|^[A-Za-z]:([/\\])', 'tokens');
17+
18+
if isempty(matches)
19+
20+
r = '';
21+
if isstring(p)
22+
r = "";
23+
end
24+
25+
else
26+
27+
r = matches{1};
28+
if iscell(r)
29+
r = r{1};
2430
end
25-
end
2631

27-
if isstring(p)
28-
r = string(r);
2932
end
3033

3134
end

0 commit comments

Comments
 (0)