Skip to content

Commit de88058

Browse files
committed
expanduser scalar or empty
1 parent d8ad3c7 commit de88058

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

+stdlib/+fileio/expanduser.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
function expanded = expanduser(p)
22

33
arguments
4-
p string
4+
p string {mustBeScalarOrEmpty}
55
end
66

77
expanded = p;
88

9+
if ~startsWith(expanded, "~")
10+
return
11+
end
12+
913
home = stdlib.fileio.homedir();
1014

1115
if ~isempty(home)
12-
i = startsWith(expanded, "~");
13-
expanded(i) = fullfile(home, extractAfter(expanded(i), 1));
16+
expanded = fullfile(home, extractAfter(expanded, 1));
1417
end
1518

1619
end %function

+stdlib/+test/TestFileImpure.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ function test_expanduser(tc)
99
tc.verifyEqual(expanduser(""), "")
1010

1111
tc.verifyFalse(startsWith(expanduser('~/foo'), "~"))
12-
tc.verifyFalse(any(startsWith(expanduser(["~/abc", "~/123"]), "~")))
1312

1413
tc.verifyTrue(endsWith(expanduser('~/foo'), "foo"))
15-
tc.verifyTrue(all(endsWith(expanduser(["~/abc", "~/123"]), ["abc", "123"])))
1614
end
1715

1816

0 commit comments

Comments
 (0)