Skip to content

Commit 63d4e1a

Browse files
committed
use strncmp, strcat to simplify/dedupe"
1 parent 6083be5 commit 63d4e1a

File tree

7 files changed

+29
-54
lines changed

7 files changed

+29
-54
lines changed

+stdlib/absolute.m

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,9 @@
4444
b = stdlib.posix(b);
4545

4646
if stdlib.is_absolute(b)
47-
if ischar(c)
48-
c = strcat(b, '/', c);
49-
else
50-
c = b + "/" + c;
51-
end
47+
c = strcat(b, "/", c);
5248
else
53-
if ischar(c)
54-
c = strcat(pwd(), '/', b, '/', c);
55-
else
56-
c = pwd() + "/" + b + "/" + c;
57-
end
49+
c = strcat(pwd(), "/", b, "/", c);
5850
end
5951

6052
c = stdlib.drop_slash(c);

+stdlib/expanduser.m

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@
1616
e = stdlib.drop_slash(p);
1717

1818
L = stdlib.len(e);
19-
if ~L
19+
if ~L || ~strncmp(e, "~", 1) || (L > 1 && ~strncmp(e, "~/", 2))
2020
return
2121
end
2222

23-
if ischar(e)
24-
ng = e(1) ~= '~' || (L > 1 && e(1) == '~' && e(2) ~= '/');
25-
else
26-
ng = ~startsWith(e, "~") || (L > 1 && ~startsWith(e, "~/"));
27-
end
28-
if ng, return, end
29-
3023
home = stdlib.homedir(use_java);
3124

3225
if stdlib.len(home) == 0

+stdlib/join.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
b = stdlib.drop_slash(base);
1717
o = stdlib.drop_slash(other);
1818

19-
if startsWith(o, "/") || (ispc && stdlib.is_absolute(o, false))
19+
if strncmp(o, "/", 1) || (ispc && stdlib.is_absolute(o, false))
2020
p = o;
2121
return
2222
end
@@ -36,8 +36,8 @@
3636

3737
end
3838

39-
%!assert(join("", ""), "")
40-
%!assert(join("", "b"), "b")
41-
%!assert(join("a", ""), "a")
42-
%!assert(join("a", "b"), "a/b")
43-
%!assert(join("a", "/b/c"), "/b/c")
39+
%!assert(join("", "", 1), "")
40+
%!assert(join("", "b", 1), "b")
41+
%!assert(join("a", "", 1), "a")
42+
%!assert(join("a", "b", 1), "a/b")
43+
%!assert(join("a", "/b/c", 1), "/b/c")

+stdlib/normalize.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@
6969
end
7070

7171

72-
%!assert(normalize("."), ".")
73-
%!assert(normalize("./"), ".")
74-
%!assert(normalize("a/.."), ".")
75-
%!assert(normalize("a/../b"), "b")
76-
%!assert(normalize("a/./b"), "a/b")
77-
%!assert(normalize("a/./b/.."), "a")
78-
%!assert(normalize(""), ".")
72+
%!assert(normalize(".",1), ".")
73+
%!assert(normalize("./",1), ".")
74+
%!assert(normalize("a/..",1), ".")
75+
%!assert(normalize("a/../b",1), "b")
76+
%!assert(normalize("a/./b",1), "a/b")
77+
%!assert(normalize("a/./b/..",1), "a")
78+
%!assert(normalize("",1), ".")

+stdlib/parent.m

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
if is_root_stub(p)
1515
% 2 or 3 char drive letter
1616
if stdlib.len(p) == 2
17-
if ischar(p)
18-
p = strcat(p, '/');
19-
else
20-
p = p + "/";
21-
end
17+
p = strcat(p, "/");
2218
end
2319
return
2420
end

+stdlib/root.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@
1717

1818
r = stdlib.root_name(p);
1919

20-
if strlength(r) == 0
21-
if startsWith(p, "/")
20+
if ~stdlib.len(r)
21+
if strncmp(p, "/", 1)
2222
r = "/";
2323
end
2424

2525
return
2626
end
2727

28-
if ispc && r == p
28+
if ispc && strcmp(r, p)
2929
return
3030
end
3131

32-
r = r + "/";
32+
r = strcat(r, "/");
3333

3434
end
3535

36-
%!assert(root(''), '')
37-
%!assert(root('/'), '/')
36+
%!assert(root('',0), '')
37+
%!assert(root('/',0), '/')
3838
%!test
3939
%! if ispc
40-
%! assert(root('C:\'), 'C:/')
41-
%! assert(root('C:/'), 'C:/')
42-
%! assert(root('C:'), 'C:')
43-
%! assert(root('C'), '')
40+
%! assert(root('C:\',0), 'C:/')
41+
%! assert(root('C:/',0), 'C:/')
42+
%! assert(root('C:',0), 'C:')
43+
%! assert(root('C',0), '')
4444
%! endif

+stdlib/with_suffix.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@
2323

2424
if strcmp(r, '.')
2525
f = s;
26-
elseif ischar(r)
27-
f = strcat(r, '/', s);
2826
else
29-
f = r + "/" + s;
27+
f = strcat(r, "/", s);
3028
end
3129

32-
if ischar(r)
33-
f = strcat(f, suffix);
34-
else
35-
f = f + suffix;
36-
end
30+
f = strcat(f, suffix);
3731

3832
end
3933

0 commit comments

Comments
 (0)