|
9 | 9 | %%% Inputs |
10 | 10 | % * p: path to make absolute |
11 | 11 | % * base: if present, base on this instead of cwd |
12 | | -% * expand_tilde: expand ~ to username if present |
13 | 12 | %%% Outputs |
14 | 13 | % * c: absolute path |
15 | 14 | % |
16 | 15 | % does not normalize path |
17 | 16 | % non-existant path is made absolute relative to pwd |
18 | 17 |
|
19 | | -function c = absolute(p, base, expand_tilde) |
| 18 | +function c = absolute(p, base) |
20 | 19 | arguments |
21 | 20 | p {mustBeTextScalar} |
22 | | - base {mustBeTextScalar} = '' |
23 | | - expand_tilde (1,1) logical = true |
24 | | -end |
25 | | - |
26 | | -if expand_tilde |
27 | | - c = stdlib.expanduser(p); |
28 | | -else |
29 | | - c = p; |
| 21 | + base {mustBeTextScalar} = pwd() |
30 | 22 | end |
31 | 23 |
|
| 24 | +c = p; |
32 | 25 | if stdlib.is_absolute(c) |
33 | 26 | return |
34 | 27 | end |
35 | 28 |
|
36 | | -if strlength(base) == 0 |
37 | | - b = pwd(); |
38 | | -elseif expand_tilde |
39 | | - b = stdlib.expanduser(base); |
| 29 | +if strlength(base) |
| 30 | + b = stdlib.absolute(base); |
40 | 31 | else |
41 | | - b = base; |
42 | | -end |
43 | | - |
44 | | -if ~stdlib.is_absolute(b) |
45 | | - b = strcat(pwd(), '/', b); |
| 32 | + b = pwd(); |
46 | 33 | end |
47 | 34 |
|
48 | | -if strlength(c) == 0 |
49 | | - c = b; |
50 | | -else |
| 35 | +if strlength(c) |
51 | 36 | c = strcat(b, '/', c); |
52 | | -end |
53 | | - |
54 | | -if isstring(p) |
55 | | - c = string(c); |
| 37 | +else |
| 38 | + c = b; |
56 | 39 | end |
57 | 40 |
|
58 | 41 | end |
59 | 42 |
|
60 | 43 |
|
61 | | -%!assert(absolute('', '', false), pwd) |
62 | | -%!assert(absolute('a/b', '', false), strcat(pwd(), '/a/b')) |
| 44 | +%!assert(absolute('', ''), pwd) |
| 45 | +%!assert(absolute('a/b', ''), strcat(pwd(), '/a/b')) |
0 commit comments