Skip to content

Commit 7178b53

Browse files
committed
make stdlib.absolute_path, same as stdlib.canonical
1 parent 503d135 commit 7178b53

File tree

5 files changed

+37
-14
lines changed

5 files changed

+37
-14
lines changed

+stdlib/+test/TestFilePure.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,33 +59,33 @@ function test_is_absolute_path(tc)
5959
tc.verifyFalse(is_absolute_path("c"))
6060
end
6161

62-
function test_canonical(tc)
62+
function test_absolute_path(tc)
6363

64-
import stdlib.canonical
64+
import stdlib.absolute_path
6565

66-
tc.assumeTrue(usejava("jvm"), "Java required for canonical")
66+
tc.assumeTrue(usejava("jvm"), "Java required for absolute_path")
6767

68-
tc.verifyEmpty(canonical(string.empty))
69-
tc.verifyEqual(canonical(""), string(pwd))
68+
tc.verifyEmpty(absolute_path(string.empty))
69+
tc.verifyEqual(absolute_path(""), string(pwd))
7070

71-
pabs = canonical('2foo');
72-
pabs2 = canonical('4foo');
71+
pabs = absolute_path('2foo');
72+
pabs2 = absolute_path('4foo');
7373
tc.verifyFalse(startsWith(pabs, "2"))
7474
tc.verifyTrue(strncmp(pabs, pabs2, 2))
7575

76-
par1 = canonical("../2foo");
76+
par1 = absolute_path("../2foo");
7777
tc.verifyNotEmpty(par1)
7878
tc.verifyFalse(contains(par1, ".."))
7979

80-
par2 = canonical("../4foo");
80+
par2 = absolute_path("../4foo");
8181
tc.verifyTrue(strncmp(par2, pabs2, 2))
8282

83-
pt1 = canonical("bar/../2foo");
83+
pt1 = absolute_path("bar/../2foo");
8484
tc.verifyNotEmpty(pt1)
8585
tc.verifyFalse(contains(pt1, ".."))
8686

87-
va = canonical("2foo");
88-
vb = canonical("4foo");
87+
va = absolute_path("2foo");
88+
vb = absolute_path("4foo");
8989
tc.verifyFalse(startsWith(va, "2"))
9090
tc.verifyTrue(strncmp(va, vb, 2))
9191

+stdlib/+test/TestWindowsCOM.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function test_shortname(tc)
1414
tc.verifyTrue(endsWith(short, 'notepad.exe'), "Short name should end with 'notepad.exe'")
1515
tc.verifyTrue(contains(short, "MICROS~1"))
1616

17-
tc.verifyEqual(stdlib.canonical(short), test_file)
17+
tc.verifyEqual(stdlib.absolute_path(short), test_file)
1818

1919
end
2020

+stdlib/absolute_path.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function abspath = absolute_path(p)
2+
%% absolute_path(p)
3+
% path need not exist, but absolute path is returned
4+
%
5+
% NOTE: some network file systems are not resolvable by Matlab Java
6+
% subsystem, but are sometimes still valid--so return
7+
% unmodified path if this occurs.
8+
%
9+
% This also resolves Windows short paths to full long paths.
10+
%
11+
%%% Inputs
12+
% * p: path to make absolute
13+
%%% Outputs
14+
% * abspath: absolute path, if determined
15+
16+
arguments
17+
p string {mustBeScalarOrEmpty}
18+
end
19+
20+
abspath = stdlib.fileio.absolute_path(p);
21+
22+
end

+stdlib/canonical.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function abspath = canonical(p)
22
%% canonical(p)
3+
% yes this is the same as absolute_path
34
% path need not exist, but absolute path is returned
45
%
56
% NOTE: some network file systems are not resolvable by Matlab Java

+stdlib/expanduser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
%%% Outputs
1111
% * expanded: expanded path
1212
%
13-
% See also CANONICAL
13+
% See also absolute_path
1414

1515
arguments
1616
p string

0 commit comments

Comments
 (0)