Skip to content

Commit d761731

Browse files
committed
expanduser: does not drop slash
this speeds up this frequently used function and reduces function overlap
1 parent 6006c73 commit d761731

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

+stdlib/expanduser.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,25 @@
1212
p (1,1) string
1313
end
1414

15-
e = stdlib.drop_slash(p);
15+
e = stdlib.posix(p);
1616

1717
L = stdlib.len(e);
1818
if ~L || ~startsWith(e, "~") || (L > 1 && ~startsWith(e, "~/"))
1919
return
2020
end
2121

2222
home = stdlib.homedir();
23+
if ~stdlib.len(home), return, end
2324

24-
if stdlib.len(home) == 0
25-
return
26-
end
27-
28-
d = home;
2925
if L < 2
30-
e = d;
26+
e = home;
3127
return
3228
end
3329

3430
if ischar(e)
35-
e = strcat(d, '/', e(3:end));
31+
e = strcat(home, '/', e(3:end));
3632
else
37-
e = d + "/" + extractAfter(e, 2);
33+
e = home + "/" + extractAfter(e, 2);
3834
end
3935

4036
end

test/TestFileImpure.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
p_is_writable = {{pwd(), true}, {"not-exists", false}, {"", false}};
55

66
p_expand = {{"", ""}, {"~abc", "~abc"}, {"~", stdlib.homedir()}, ...
7-
{"~/c", stdlib.homedir() + "/c"}, {'~/////c', stdlib.homedir() + "/c"}};
7+
{"~/c", stdlib.homedir() + "/c"}, {'~//c', stdlib.homedir() + "//c"}};
88

99
p_same = {...
1010
{"","", false}, ...

0 commit comments

Comments
 (0)