Skip to content

Commit

Permalink
added explicit starts/endsWith functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Beliy Nikita committed Feb 22, 2021
1 parent 568e0cf commit e68a18c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
23 changes: 23 additions & 0 deletions +bids/+internal/endsWith.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function res = endsWith(str, pat)
%
% Checks id character array 'str' ends with 'pat'
%
% USAGE res = bids.internal.endsWith(str, pat)
%
% str - character array
% pat - character array
%
% __________________________________________________________________________
%
% Based on spm_file.m and spm_select.m from SPM12.
% __________________________________________________________________________

% Copyright (C) 2011-2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
res = false;
l_pat = length(pat);
if l_pat > length(str)
return;
end
res = strcmp(str(end - l_pat +1 : end), pat);

end
2 changes: 1 addition & 1 deletion +bids/+internal/get_metadata.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
metafile = cellstr(metafile);

for i = 1:numel(metafile)
if endsWith(metafile{i}, '.json')
if bids.internal.endsWith(metafile{i}, '.json')
meta = update_metadata(meta, bids.util.jsondecode(metafile{i}), metafile{i});
else
meta.filename = metafile{i};
Expand Down
23 changes: 23 additions & 0 deletions +bids/+internal/startsWith.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function res = startsWith(str, pat)
%
% Checks id character array 'str' starts with 'pat'
%
% USAGE res = bids.internal.startsWith(str, pat)
%
% str - character array
% pat - character array
%
% __________________________________________________________________________
%
% Based on spm_file.m and spm_select.m from SPM12.
% __________________________________________________________________________

% Copyright (C) 2011-2018 Guillaume Flandin, Wellcome Centre for Human Neuroimaging
res = false;
l_pat = length(pat);
if l_pat > length(str)
return;
end
res = strcmp(str(1 : l_pat), pat);

end
2 changes: 1 addition & 1 deletion +bids/derivate.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
mkdir(out_dir);
end
% copy data file
if endsWith(file.ext, '.gz')
if bids.internal.endsWith(file.ext, '.gz')
gunzip(data_file, out_dir);
else
[status,message,messageId] = copyfile(data_file, [out_path file.ext]);
Expand Down
4 changes: 2 additions & 2 deletions +bids/layout.m
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
if strcmp(candidates{ii}, file_list{i})
continue;
end
if endsWith(candidates{ii}, '.json')
if bids.internal.endsWith(candidates{ii}, '.json')
continue
end
match = regexp(candidates{ii}, ['_' suffix '\..*$'], 'match');
Expand Down Expand Up @@ -246,7 +246,7 @@
if strcmp(candidates{ii}, file_list{i})
continue;
end
if endsWith(candidates{ii}, '.json')
if bids.internal.endsWith(candidates{ii}, '.json')
continue
end
match = regexp(candidates{ii}, ['_' suffix '\..*$'], 'match');
Expand Down

0 comments on commit e68a18c

Please sign in to comment.