Skip to content

Commit 1785f51

Browse files
committed
improve substring indexing
root_name: dedupe code paths
1 parent ee77934 commit 1785f51

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

+stdlib/expanduser.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
if ischar(e)
3131
e = strcat(home, '/', e(3:end));
3232
else
33-
e = home + "/" + extractAfter(e, 2);
33+
e = home + "/" + e{1}(3:end);
3434
end
3535

3636
end

+stdlib/is_absolute.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
if ischar(p)
2323
s = p(3); %#ok<UNRCH>
2424
else
25-
s = extractBetween(p, 3, 3);
25+
s = p{1}(3);
2626
end
2727
y = strlength(stdlib.root_name(p)) && (strcmp(s, '/') || strcmp(s, '\'));
2828
else

+stdlib/normalize.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
if isempty(j)
4444
n = "";
4545
else
46-
n = extractBefore(n, j(end));
46+
n = n{1}(1:j(end)-1);
4747
end
4848
end
4949
elseif all(parts(i) ~= [".", ""])

+stdlib/parent.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
elseif ischar(p)
3535
p = p(1:j(end)-1);
3636
else
37-
p = extractBefore(p, j(end));
37+
p = p{1}(1:j(end)-1);
3838
end
3939

4040
if is_root_stub(p)

+stdlib/private/h5save_scalar.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ function h5save_scalar(file, hpath, A)
4444
case 'double', t = 'H5T_NATIVE_DOUBLE';
4545
case 'single', t = 'H5T_NATIVE_FLOAT';
4646
case {'int8', 'int16', 'int32', 'int64'}
47-
t = "H5T_STD_I" + extractBetween(C, 4, strlength(C)) + "LE";
47+
t = "H5T_STD_I" + C(4:end) + "LE";
4848
case {'uint8', 'uint16', 'uint32', 'uint64'}
49-
t = "H5T_STD_U" + extractBetween(C, 5, strlength(C)) + "LE";
49+
t = "H5T_STD_U" + C(5:end) + "LE";
5050
otherwise, error('h5save:class2h5t: unknown data class %s', class(A))
5151
end
5252

+stdlib/private/strlength.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
% for GNU Octave until it builds in strlength
44

55
function L = strlength(s)
6-
7-
L = [];
6+
arguments
7+
s {mustBeTextScalar}
8+
end
89

910
if ischar(s)
1011
L = length(s);
11-
elseif isstring(s)
12+
else
1213
L = builtin('strlength', char(s));
1314
% bug in Matlab at least through R2025a confirmed by Xinyue Xia of Mathworks Technical Support
1415
% only works for char and scalar strings until fixed by Mathworks.

+stdlib/root_name.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77

88
function r = root_name(p)
99
arguments
10-
p (1,1) string
10+
p {mustBeTextScalar}
1111
end
1212

1313
r = "";
1414

15-
if ~ispc || strlength(p) < 2, return, end
15+
if ~ispc || strlength(p) < 2
16+
return
17+
end
18+
19+
c = char(p);
20+
21+
if c(2) == ':' && isletter(c(1))
22+
r = c(1:2);
23+
end
1624

17-
if ischar(p)
18-
if p(2) == ':' && isletter(p(1)) %#ok<UNRCH>
19-
r = p(1:2);
20-
end
21-
else
22-
if extractBetween(p, 2, 2) == ":" && isletter(extractBetween(p, 1, 1))
23-
r = extractBetween(p, 1, 2);
24-
end
25+
if isstring(p)
26+
r = string(r);
2527
end
2628

2729
end

private/publish_gen_index_html.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function publish_gen_index_html(pkg_name, tagline, project_url, outdir)
2424

2525
%% Git info
2626
repo = gitrepo(pkg.path);
27-
git_txt = "Git branch / commit: " + repo.CurrentBranch.Name + " " + extractBefore(repo.LastCommit.ID, 8);
27+
git_txt = "Git branch / commit: " + repo.CurrentBranch.Name + " " + repo.LastCommit.ID{1}(1:8);
2828

2929
%% generate docs
3030
readme = fullfile(outdir, "index.html");

0 commit comments

Comments
 (0)