Skip to content

Commit 00f0385

Browse files
committed
remove unneeded string()
1 parent 7f0e805 commit 00f0385

File tree

9 files changed

+21
-24
lines changed

9 files changed

+21
-24
lines changed

+stdlib/file_checksum.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
function hash = file_checksum(file, method)
1313
arguments
14-
file (1,1) string {mustBeFile}
14+
file (1,1) string
1515
method (1,1) string
1616
end
1717

@@ -28,7 +28,7 @@
2828
end
2929

3030
fid = fopen(file, 'r');
31-
assert(fid > 0, "could not open %s", file)
31+
assert(fid > 0, "could not open file %s", file)
3232

3333
while ~feof(fid)
3434
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/security/MessageDigest.html#update(byte)
@@ -41,7 +41,7 @@
4141

4242
hash = sprintf('%.2x', hash);
4343

44-
try %#ok<TRYNC>
44+
if isa(file, "string")
4545
hash = string(hash);
4646
end
4747

+stdlib/get_shell.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
s = getenv("SHELL");
88

9-
try %#ok<TRYNC>
9+
d = "";
10+
11+
if isa(d, "string")
1012
s = string(s);
1113
end
1214

+stdlib/handle2filename.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
n = stdlib.posix(fopen(fileHandle));
1212
end
1313

14-
try %#ok<TRYNC>
15-
n = string(n);
16-
end
17-
1814
end
1915

2016
%!assert(handle2filename(0), "stdin")

+stdlib/read_symlink.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@
2121
r = stdlib.absolute(p, "", false, true);
2222

2323
% https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/nio/file/Files.html#readSymbolicLink(java.nio.file.Path)
24-
t = string(java.nio.file.Files.readSymbolicLink(java.io.File(r).toPath()));
24+
t = java.nio.file.Files.readSymbolicLink(java.io.File(r).toPath());
2525
else
2626
[ok, t] = isSymbolicLink(p);
2727
if ~ok, return, end
28-
t = string(t);
2928
end
3029

3130
r = stdlib.posix(t);

+stdlib/windows_shortname.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
% https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/ch28h2s7
77
% https://www.mathworks.com/matlabcentral/fileexchange/48950-short-path-name-on-windows-com-server
88

9-
function short = windows_shortname(p)
9+
function s = windows_shortname(p)
1010
arguments
1111
p (1,1) string
1212
end
1313

14-
short = string.empty;
14+
s = string.empty;
1515

1616
if ~ispc
1717
return
@@ -20,12 +20,12 @@
2020
fso = actxserver('Scripting.FileSystemObject');
2121

2222
if isfolder(p)
23-
short = fso.GetFolder(p).ShortPath;
23+
s = fso.GetFolder(p).ShortPath;
2424
elseif isfile(p)
25-
short = fso.GetFile(p).ShortPath;
25+
s = fso.GetFile(p).ShortPath;
2626
end
2727

28-
short = string(short);
28+
s = string(s);
2929

3030
delete(fso);
3131

test/TestCanonical.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{"", ""}, {"not-exist", "not-exist"}, {"a/../b", "b"}, ...
66
{"~", test_homedir()}, {"~/", test_homedir()}, ...
77
{"~/..", stdlib.parent(test_homedir())}, ...f
8-
{mfilename("fullpath") + ".m/..", stdlib.parent(string(mfilename("fullpath")))}};
8+
{mfilename("fullpath") + ".m/..", stdlib.parent(mfilename("fullpath"))}};
99
end
1010

1111

test/TestFilePure.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ function test_join(tc, p_join)
118118
end
119119

120120
function test_filename(tc, p_filename)
121-
tc.verifyEqual(stdlib.filename(p_filename{1}), string(p_filename{2}))
121+
tc.verifyEqual(stdlib.filename(p_filename{1}), p_filename{2})
122122
end
123123

124124
function test_suffix(tc, p_suffix)
125-
tc.verifyEqual(stdlib.suffix(p_suffix{1}), string(p_suffix{2}))
125+
tc.verifyEqual(stdlib.suffix(p_suffix{1}), p_suffix{2})
126126
end
127127

128128

test/TestResolve.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function setup_workdir(tc)
2424

2525
function test_absolute(tc)
2626

27-
td = stdlib.posix(string(pwd()));
27+
td = stdlib.posix(pwd());
2828

2929
tc.verifyEqual(stdlib.absolute(""), td)
3030
tc.verifyEqual(stdlib.absolute("",""), td)
@@ -46,7 +46,7 @@ function test_resolve_non_exist(tc)
4646
import matlab.unittest.constraints.StartsWithSubstring
4747
import matlab.unittest.constraints.ContainsSubstring
4848

49-
td = stdlib.posix(string(pwd()));
49+
td = stdlib.posix(pwd());
5050

5151
% all non-existing files
5252

@@ -77,11 +77,11 @@ function test_resolve_non_exist(tc)
7777

7878
function test_resolve_exist(tc)
7979

80-
td = stdlib.posix(string(pwd()));
80+
td = stdlib.posix(pwd());
8181

8282
r = stdlib.parent(mfilename('fullpath'));
8383
rp = stdlib.parent(r);
84-
tc.verifyEqual(stdlib.resolve(rp), string(stdlib.parent(r)))
84+
tc.verifyEqual(stdlib.resolve(rp), stdlib.parent(r))
8585

8686
h = stdlib.homedir();
8787
tc.verifyEqual(stdlib.resolve("~"), h)

test/TestWindowsCOM.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function test_short_folder(tc)
2020

2121
tc.assumeTrue(ispc, "Windows only")
2222

23-
progdir = string(getenv("PROGRAMFILES"));
23+
progdir = stdlib.posix(getenv("PROGRAMFILES"));
2424
tc.assumeThat(progdir, IsFolder, "env:PROGRAMFILES is not a directory")
2525

2626
short = stdlib.windows_shortname(progdir);
2727

2828
tc.verifySubstring(short, "PROGRA~1")
2929

30-
tc.verifyEqual(stdlib.canonical(short), stdlib.posix(progdir))
30+
tc.verifyEqual(stdlib.canonical(short), progdir)
3131

3232
end
3333

0 commit comments

Comments
 (0)