Skip to content

Commit a02a55c

Browse files
committed
most functions require scalar, non-empty input for clarity
1 parent 3fc63c3 commit a02a55c

29 files changed

+67
-78
lines changed

+stdlib/+fileio/absolute_path.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
function abspath = absolute_path(p)
22
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getAbsolutePath()
33
arguments
4-
p string {mustBeScalarOrEmpty}
4+
p (1,1) string
55
end
66

77
% have to expand ~ first (like C++ filesystem::path::absolute)
88
abspath = stdlib.fileio.expanduser(p);
99

10-
if isempty(abspath) || abspath == ""
10+
if abspath == ""
1111
return
1212
end
1313

@@ -21,6 +21,6 @@
2121
abspath = stdlib.fileio.join(pwd, abspath);
2222
end
2323

24-
abspath = stdlib.posix(java.io.File(abspath).getAbsolutePath());
24+
abspath = stdlib.fileio.posix(java.io.File(abspath).getAbsolutePath());
2525

2626
end % function

+stdlib/+fileio/canonical.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
function c = canonical(p)
22
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getCanonicalPath()
33
arguments
4-
p string {mustBeScalarOrEmpty}
4+
p (1,1) string
55
end
66

77
% have to expand ~ first (like C++ filesystem::path::absolute)
88
c = stdlib.fileio.expanduser(p);
99

10-
if isempty(c)
11-
return
12-
end
13-
1410
if ispc && startsWith(c, "\\")
1511
% UNC path is not canonicalized
1612
return

+stdlib/+fileio/expanduser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function e = expanduser(p)
22

33
arguments
4-
p string {mustBeScalarOrEmpty}
4+
p (1,1) string
55
end
66

77
e = p;

+stdlib/+fileio/filename.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function p = filename(path)
22
% FILENAME filename (including suffix) without directory
33
arguments
4-
path string
4+
path (1,1) string
55
end
66

77
% NOT https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#getName()

+stdlib/+fileio/is_absolute_path.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
function isabs = is_absolute_path(apath)
22
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#isAbsolute()
33
arguments
4-
apath string {mustBeScalarOrEmpty}
5-
end
6-
7-
if isempty(apath)
8-
isabs = logical.empty();
9-
return
4+
apath (1,1) string
105
end
116

127
% expanduser() here to work like C++ filesystem::path::is_absolute()

+stdlib/+fileio/is_exe.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/File.html#canExecute()
44

55
arguments
6-
file string {mustBeScalarOrEmpty}
7-
end
8-
9-
if isempty(file)
10-
ok = logical.empty;
11-
return
6+
file (1,1) string
127
end
138

149
ok = java.io.File(file).canExecute();

+stdlib/+fileio/is_readable.m

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isReadable(java.nio.file.Path)
44

55
arguments
6-
file string {mustBeScalarOrEmpty}
7-
end
8-
9-
if isempty(file)
10-
ok = logical.empty;
11-
return
6+
file (1,1) string
127
end
138

149

+stdlib/+fileio/is_writable.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#isWritable(java.nio.file.Path)
44

55
arguments
6-
file string {mustBeScalarOrEmpty}
6+
file (1,1) string
77
end
88

9-
if isempty(file)
10-
ok = logical.empty;
11-
return
12-
end
13-
14-
159
ok = java.nio.file.Files.isWritable(java.io.File(stdlib.fileio.absolute_path(file)).toPath());
1610

1711
end

+stdlib/+fileio/join.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function p = join(a, b)
22
%% JOIN: join two paths with posix file separator
33
arguments
4-
a string {mustBeScalarOrEmpty}
5-
b string {mustBeScalarOrEmpty}
4+
a (1,1) string
5+
b (1,1) string
66
end
77

88
p = stdlib.fileio.posix(fullfile(a, b));

+stdlib/+fileio/normalize.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22
% normalize(p) remove redundant elements of path p
33
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Path.html#normalize()
44
arguments
5-
p string {mustBeScalarOrEmpty}
5+
p (1,1) string
66
end
77

8-
n = p;
9-
if isempty(p)
10-
return
11-
end
12-
13-
n = stdlib.fileio.posix(java.io.File(stdlib.fileio.expanduser(n)).toPath().normalize());
8+
n = stdlib.fileio.posix(java.io.File(stdlib.fileio.expanduser(p)).toPath().normalize());
149

1510
end

0 commit comments

Comments
 (0)