Skip to content

Commit 4e67737

Browse files
committed
expanduser: no posix()
1 parent eed2abd commit 4e67737

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

+stdlib/expanduser.m

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
p {mustBeTextScalar}
1313
end
1414

15-
e = stdlib.posix(char(p));
16-
15+
e = char(p);
1716
L = length(e);
18-
if L == 0 || e(1) ~= '~' || (L > 1 && ~strcmp(e(1:2), '~/'))
19-
% noop
20-
else
17+
ok = L > 0 && e(1) == '~';
18+
ok = ok && (L == 1 || e(2) == '/' || (ispc && e(2) == '\'));
19+
20+
if ok
2121
home = stdlib.homedir();
22-
if isempty(home)
23-
% noop
24-
elseif L < 2
22+
if any(L == [1,2])
2523
e = home;
2624
else
2725
e = strcat(home, '/', e(3:end));

+stdlib/homedir.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
h = getenv("HOME");
99
end
1010

11-
h = stdlib.posix(h);
12-
1311
end
1412

1513
%!assert(!isempty(homedir()))

test/TestExpanduser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
{"~abc", "~abc"}, ...
77
{'~', stdlib.homedir()},...
88
{"~", string(stdlib.homedir())}, ...
9-
{'~/', strcat(stdlib.homedir(), '/')},...
10-
{"~/", stdlib.homedir() + "/"}, ...
9+
{'~/',stdlib.homedir()},...
10+
{"~/", string(stdlib.homedir())}, ...
1111
{"~/c", stdlib.homedir() + "/c"}, ...
1212
{"~//c", stdlib.homedir() + "//c"}};
1313
end

0 commit comments

Comments
 (0)