Skip to content

Commit 5217d23

Browse files
committed
canonical, resolve: any size array
1 parent 1a5dde1 commit 5217d23

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

+stdlib/+native/canonical.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
function c = canonical(file, strict)
2+
arguments
3+
file string
4+
strict (1,1) logical = false
5+
end
6+
7+
rp = matlab.io.internal.filesystem.resolvePath(file);
8+
c = string({rp.ResolvedPath});
29

3-
if stdlib.strempty(file)
4-
c = "";
10+
if strict
511
return
612
end
713

8-
p = matlab.io.internal.filesystem.resolvePath(file);
9-
c = p.ResolvedPath;
10-
11-
if ~strict && stdlib.strempty(c)
12-
c = string(stdlib.normalize(file));
14+
for i = 1:numel(file)
15+
if strlength(c(i)) == 0 && strlength(file(i)) > 0
16+
c(i) = stdlib.normalize(file(i));
17+
end
1318
end
1419

1520
end

+stdlib/+native/normalize.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
function n = normalize(p)
2+
arguments
3+
p (1,1) string
4+
end
25

3-
n = stdlib.posix(string(p));
6+
n = stdlib.posix(p);
47

58
uncslash = ispc() && startsWith(n, "//");
69

+stdlib/canonical.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
function c = canonical(p, strict, backend)
1616
arguments
17-
p {mustBeTextScalar}
17+
p string
1818
strict (1,1) logical = false
1919
backend (1,:) string = ["native", "legacy"]
2020
end
2121

22-
fun = hbackend(backend, "canonical", 'R2024a');
23-
24-
c = fun(p, strict);
22+
if isscalar(p)
23+
fun = hbackend(backend, "canonical", 'R2024a');
24+
c = fun(p, strict);
25+
else
26+
c = stdlib.native.canonical(p, strict);
27+
end
2528

2629
end

+stdlib/resolve.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
function r = resolve(p)
1212
arguments
13-
p {mustBeTextScalar}
13+
p string
1414
end
1515

1616
r = stdlib.canonical(stdlib.absolute(p));

0 commit comments

Comments
 (0)