|
1 | 1 | %% PARENT parent directory of path |
2 | 2 | % |
3 | 3 | %% Examples: |
4 | | -% parent("a/b/c") == "a/b" |
5 | | -% parent("a/b/c/") == "a/b" |
6 | | -% |
7 | | -% MEX is about 10x faster than plain Matlab for this function |
| 4 | +% stdlib.parent("a/b/c") == "a/b" |
| 5 | +% stdlib.parent("a/b/c/") == "a/b" |
8 | 6 |
|
9 | | -function p = parent(pth) |
| 7 | +function p = parent(pth, method) |
10 | 8 | arguments |
11 | 9 | pth {mustBeTextScalar} |
| 10 | + method (1,:) string = ["java", "python", "native"] |
12 | 11 | end |
13 | 12 |
|
14 | | -if stdlib.has_java() |
15 | | - p = stdlib.java.parent(pth); |
16 | | -elseif stdlib.has_python() |
17 | | - p = stdlib.python.parent(pth); |
18 | | -else |
19 | | - p = stdlib.native.parent(pth); |
20 | | -end |
| 13 | +fun = choose_method(method, "parent"); |
21 | 14 |
|
22 | | -end |
| 15 | +p = fun(pth); |
23 | 16 |
|
24 | | -%!assert(parent("/a/b/c"), fullfile('/a','b')) |
25 | | -%!assert(parent("/a/b/c/"), fullfile('/a','b')) |
26 | | -%!assert(parent('/a///b'), fullfile('/a')) |
27 | | -%!assert(parent('a/b/'), 'a') |
28 | | -%!assert(parent('a//b/'), 'a') |
29 | | -%!assert(parent('a//b'), 'a') |
30 | | -%!test |
31 | | -%! if ispc |
32 | | -%! assert(parent('c:/a'), 'c:\') |
33 | | -%! assert(parent('c:\a\'), 'c:\') |
34 | | -%! assert(parent('c:\'), 'c:\') |
35 | | -%! assert(parent('c:'), 'c:\') |
36 | | -%! end |
| 17 | +end |
0 commit comments