diff --git a/+stdlib/absolute.m b/+stdlib/absolute.m index 56bcafb..0763b80 100644 --- a/+stdlib/absolute.m +++ b/+stdlib/absolute.m @@ -19,14 +19,14 @@ function c = absolute(p, base, expand_tilde, use_java) arguments p (1,1) string - base string {mustBeScalarOrEmpty} = string.empty + base (1,1) string = "" expand_tilde (1,1) logical = true use_java (1,1) logical = false end cwd = stdlib.posix(pwd()); -if (isempty(p) || strlength(p) == 0) && (isempty(base) || strlength(base) == 0) +if strlength(p) == 0 && strlength(base) == 0 c = cwd; return end @@ -42,10 +42,10 @@ else % .getAbsolutePath(), .toAbsolutePath() % default is Documents/Matlab, which is probably not wanted. - if isempty(base) || strlength(base) == 0 + if strlength(base) == 0 c = cwd + "/" + c; else - d = stdlib.absolute(base, string.empty, expand_tilde, use_java); + d = stdlib.absolute(base, "", expand_tilde, use_java); if isempty(c) || strlength(c) == 0 c = d; else diff --git a/+stdlib/h5save.m b/+stdlib/h5save.m index 829c066..9a6e7dc 100644 --- a/+stdlib/h5save.m +++ b/+stdlib/h5save.m @@ -24,7 +24,7 @@ function h5save(filename, varname, A, opts) varname (1,1) string {mustBeNonzeroLengthText} A {mustBeNonempty} opts.size (1,:) double {mustBeInteger,mustBeNonnegative} = [] - opts.type string {mustBeScalarOrEmpty} = string.empty + opts.type (1,1) string = "" end if isnumeric(A) diff --git a/+stdlib/h5variables.m b/+stdlib/h5variables.m index 07a0386..f0ae0af 100644 --- a/+stdlib/h5variables.m +++ b/+stdlib/h5variables.m @@ -11,10 +11,10 @@ function names = h5variables(file, group) arguments file (1,1) string {mustBeFile} - group string {mustBeScalarOrEmpty} = string.empty + group (1,1) string = "" end -if isempty(group) || strlength(group) == 0 +if strlength(group) == 0 finf = h5info(file); else finf = h5info(file, group); diff --git a/+stdlib/is_readable.m b/+stdlib/is_readable.m index 6106a29..c947098 100644 --- a/+stdlib/is_readable.m +++ b/+stdlib/is_readable.m @@ -11,7 +11,7 @@ if use_java % java is about 10x slower than fileattrib % needs absolute() - file = stdlib.absolute(file, string.empty, false, use_java); + file = stdlib.absolute(file, "", false, use_java); ok = java.nio.file.Files.isReadable(java.io.File(file).toPath()); else diff --git a/+stdlib/is_regular_file.m b/+stdlib/is_regular_file.m index cad8549..e06d6b0 100644 --- a/+stdlib/is_regular_file.m +++ b/+stdlib/is_regular_file.m @@ -8,7 +8,7 @@ opt = java.nio.file.LinkOption.values; % needs absolute() -p = stdlib.absolute(p, string.empty, false, true); +p = stdlib.absolute(p, "", false, true); isreg = java.nio.file.Files.isRegularFile(java.io.File(p).toPath(), opt); diff --git a/+stdlib/is_symlink.m b/+stdlib/is_symlink.m index 1f7379f..fd01a64 100644 --- a/+stdlib/is_symlink.m +++ b/+stdlib/is_symlink.m @@ -11,7 +11,7 @@ if isMATLABReleaseOlderThan("R2024b") % must be absolute path % NOT .canonical or symlink is gobbled! - p = stdlib.absolute(p, string.empty, false, true); + p = stdlib.absolute(p, "", false, true); ok = java.nio.file.Files.isSymbolicLink(java.io.File(p).toPath()); else ok = isSymbolicLink(p); diff --git a/+stdlib/is_writable.m b/+stdlib/is_writable.m index bcd1209..d1da2de 100644 --- a/+stdlib/is_writable.m +++ b/+stdlib/is_writable.m @@ -11,7 +11,7 @@ if use_java % java is about 10x slower than fileattrib % needs absolute() - file = stdlib.absolute(file, string.empty, false, use_java); + file = stdlib.absolute(file, "", false, use_java); ok = java.nio.file.Files.isWritable(java.io.File(file).toPath()); else diff --git a/+stdlib/ncsave.m b/+stdlib/ncsave.m index 58ba50d..a889166 100644 --- a/+stdlib/ncsave.m +++ b/+stdlib/ncsave.m @@ -16,7 +16,7 @@ function ncsave(filename, varname, A, opts) varname (1,1) string {mustBeNonzeroLengthText} A {mustBeNonempty} opts.dims cell = {} - opts.type string {mustBeScalarOrEmpty} = string.empty + opts.type (1,1) string = "" end if isnumeric(A) diff --git a/+stdlib/ncvariables.m b/+stdlib/ncvariables.m index e04277f..86293e4 100644 --- a/+stdlib/ncvariables.m +++ b/+stdlib/ncvariables.m @@ -11,10 +11,10 @@ function names = ncvariables(file, group) arguments file (1,1) string {mustBeFile} - group string {mustBeScalarOrEmpty} = string.empty + group (1,1) string = "" end -if isempty(group) || strlength(group) == 0 +if strlength(group) == 0 finf = ncinfo(file); else finf = ncinfo(file, group); diff --git a/+stdlib/private/coerce_ds.m b/+stdlib/private/coerce_ds.m index a543dd6..6f47ac7 100644 --- a/+stdlib/private/coerce_ds.m +++ b/+stdlib/private/coerce_ds.m @@ -2,7 +2,7 @@ % used by h5save and ncsave arguments A - dtype string {mustBeScalarOrEmpty} + dtype (1,1) string end if ischar(A) @@ -10,7 +10,7 @@ return end -if isempty(dtype) +if strlength(dtype) == 0 return end diff --git a/+stdlib/read_symlink.m b/+stdlib/read_symlink.m index e996b54..2c98e3f 100644 --- a/+stdlib/read_symlink.m +++ b/+stdlib/read_symlink.m @@ -17,7 +17,7 @@ % must be absolute path % must not be .canonical or symlink is gobbled! -r = stdlib.absolute(p, string.empty, false, true); +r = stdlib.absolute(p, "", false, true); % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path) t = java.nio.file.Files.readSymbolicLink(java.io.File(r).toPath()); diff --git a/+stdlib/resolve.m b/+stdlib/resolve.m index 3fcf476..079ffc0 100644 --- a/+stdlib/resolve.m +++ b/+stdlib/resolve.m @@ -16,6 +16,6 @@ use_java (1,1) logical = false end -r = stdlib.canonical(stdlib.absolute(p, string.empty, expand_tilde, use_java), false, use_java); +r = stdlib.canonical(stdlib.absolute(p, "", expand_tilde, use_java), false, use_java); end diff --git a/+stdlib/samepath.m b/+stdlib/samepath.m index 47064eb..cab4555 100644 --- a/+stdlib/samepath.m +++ b/+stdlib/samepath.m @@ -23,8 +23,8 @@ if use_java % needs absolute -path1 = stdlib.absolute(path1, string.empty, false, true); -path2 = stdlib.absolute(path2, string.empty, false, true); +path1 = stdlib.absolute(path1, "", false, true); +path2 = stdlib.absolute(path2, "", false, true); issame = java.nio.file.Files.isSameFile(... java.io.File(path1).toPath(), ... diff --git a/+stdlib/subprocess_run.m b/+stdlib/subprocess_run.m index 09ae018..7a714cc 100644 --- a/+stdlib/subprocess_run.m +++ b/+stdlib/subprocess_run.m @@ -28,15 +28,15 @@ function [status, stdout, stderr] = subprocess_run(cmd, opt) arguments cmd (1,:) string - opt.env struct {mustBeScalarOrEmpty} = struct.empty - opt.cwd string {mustBeScalarOrEmpty} = string.empty - opt.stdin string {mustBeScalarOrEmpty} = string.empty + opt.env (1,1) struct = struct() + opt.cwd (1,1) string = "" + opt.stdin (1,1) string = "" end %% process instantiation proc = java.lang.ProcessBuilder(""); -if ~isempty(opt.env) +if ~isempty(fieldnames(opt.env)) % requires Parallel Computing Toolbox % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ProcessBuilder.html#environment() env = proc.environment(); @@ -46,7 +46,7 @@ end end -if ~isempty(opt.cwd) +if strlength(opt.cwd) > 0 mustBeFolder(opt.cwd) % https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ProcessBuilder.html#directory(java.io.File) proc.directory(java.io.File(opt.cwd)); @@ -59,7 +59,7 @@ h = proc.start(); %% stdin pipe -if ~isempty(opt.stdin) +if strlength(opt.stdin) > 0 writer = java.io.BufferedWriter(java.io.OutputStreamWriter(h.getOutputStream())); writer.write(opt.stdin); writer.flush()