Skip to content

Commit 04fa066

Browse files
committed
root: enhance/correct Java
1 parent 906a0d6 commit 04fa066

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

+stdlib/parent.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
end
88

99
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getParent()
10-
% java was 10x slower and not correct for input like C:
10+
% java was 10x slower and not correct for input like C:/
1111

1212
p = stdlib.drop_slash(pth);
1313

+stdlib/private/jPosix.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function s = jPosix(o)
2+
3+
d = "";
4+
5+
if isempty(o)
6+
s = "";
7+
else
8+
s = o.toString();
9+
end
10+
11+
if isa(d, "string")
12+
s = string(s);
13+
end
14+
15+
s = stdlib.posix(s);
16+
17+
end

+stdlib/root.m

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,12 @@
1010
end
1111

1212

13-
r = "";
14-
if stdlib.len(p) == 0
15-
return
16-
end
17-
18-
1913
if stdlib.isoctave()
2014
o = javaObject("java.io.File", p).toPath().getRoot();
21-
if ~isempty(o)
22-
r = stdlib.posix(o.toString());
23-
end
15+
r = jPosix(o);
2416
elseif use_java
25-
r = stdlib.posix(java.io.File(p).toPath().getRoot().toString());
17+
o = java.io.File(p).toPath().getRoot();
18+
r = jPosix(o);
2619
else
2720

2821
r = stdlib.root_name(p);

0 commit comments

Comments
 (0)