Initial Commit
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
function tf = matches (str, pat, varargin)
|
||||
%MATCHES True where text equals a pattern exactly (MATLAB R2019b+).
|
||||
%
|
||||
% An owuitools compatibility shim; see contains.m for the policy.
|
||||
% Unlike `contains` this is whole-string equality, which is the point
|
||||
% of it - the two are easy to confuse and MATLAB keeps them apart.
|
||||
|
||||
if (nargin < 2)
|
||||
error ('matches: not enough input arguments');
|
||||
end
|
||||
|
||||
ignore_case = false;
|
||||
if (numel (varargin) == 2 && ischar (varargin{1}) ...
|
||||
&& strcmpi (varargin{1}, 'IgnoreCase'))
|
||||
ignore_case = logical (varargin{2});
|
||||
elseif (~isempty (varargin))
|
||||
error ('matches: the only supported option is ''IgnoreCase''');
|
||||
end
|
||||
|
||||
strs = owuitools_text_cell (str, 'matches', 'str');
|
||||
pats = owuitools_text_cell (pat, 'matches', 'pat');
|
||||
|
||||
tf = false (size (strs));
|
||||
for i = 1:numel (strs)
|
||||
for j = 1:numel (pats)
|
||||
if (ignore_case)
|
||||
hit = strcmpi (strs{i}, pats{j});
|
||||
else
|
||||
hit = strcmp (strs{i}, pats{j});
|
||||
end
|
||||
if (hit)
|
||||
tf(i) = true;
|
||||
break;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if (ischar (str))
|
||||
tf = tf(1);
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user