diff --git a/compatibility/regexp_comp.m b/compatibility/regexp_comp.m new file mode 100644 index 0000000..49a6587 --- /dev/null +++ b/compatibility/regexp_comp.m @@ -0,0 +1,12 @@ +function varargout = regexp(varargin) +% If regular expression is invalid, instead of an error it gives empty outputs, +% like Matlab does. For that we use a try...catch block; if an error is found we +% use an empty regexp to produce empty outputs +nargout = max(nargout,1); +try + [varargout{1:nargout}] = builtin('regexp', varargin{:}); +catch + varargin{2} = ''; + [varargout{1:nargout}] = builtin('regexp', varargin{:}); +end +end \ No newline at end of file diff --git a/compatibility/regexprep_comp.m b/compatibility/regexprep_comp.m new file mode 100644 index 0000000..1ce8165 --- /dev/null +++ b/compatibility/regexprep_comp.m @@ -0,0 +1,12 @@ +function varargout = regexprep(varargin) +% If regular expression is invalid, instead of an error it gives empty outputs, +% like Matlab does. For that we use a try...catch block; if an error is found we +% use an empty regexp to produce empty outputs +nargout = max(nargout,1); +try + [varargout{1:nargout}] = builtin('regexprep', varargin{:}); +catch + varargin{2} = ''; + [varargout{1:nargout}] = builtin('regexprep', varargin{:}); +end +end \ No newline at end of file diff --git a/doc/MATL_spec.pdf b/doc/MATL_spec.pdf index ef4383b..ebcd265 100644 Binary files a/doc/MATL_spec.pdf and b/doc/MATL_spec.pdf differ diff --git a/funDef.mat b/funDef.mat index 115289f..e73ef32 100644 Binary files a/funDef.mat and b/funDef.mat differ diff --git a/funDef.txt b/funDef.txt index 077cc3f..4e4ad60 100644 --- a/funDef.txt +++ b/funDef.txt @@ -703,12 +703,15 @@ XW YW ZW X -XX 2 9 2 3 1 6 max(1,sum(ismember(cellfun(@num2str, in(3:end), 'uniformoutput', false), {'start' 'end' 'tokenExtents' 'match' 'tokens' 'split' '1' '2' '3' '5' '6' '7'}))) true true true true str = {'start' 'split' 'end' 'once' 'tokenExtents' 'tokens' 'match'}; match regular expression \matlab+regexp+. With $2$ inputs: \matlab+regexp(..., ..., 'match')+. If first or second inputs are numeric they are converted to char. \matlab+'names'+ output is not supported. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'start'+, 2: \matlab+'split'+, 3: \matlab+'end'+, 4: \matlab+'once'+, 5: \matlab+'tokenExtents'+, 6: \matlab+'tokens'+, 7: \matlab+'match'+ +XX 2 9 2 3 1 6 max(1,sum(ismember(cellfun(@num2str, in(3:end), 'uniformoutput', false), {'start' 'end' 'tokenExtents' 'match' 'tokens' 'split' '1' '2' '3' '5' '6' '7'}))) true true true true str = {'start' 'split' 'end' 'once' 'tokenExtents' 'tokens' 'match'}; match regular expression \matlab+regexp+. With $2$ inputs: \matlab+regexp(..., ..., 'match')+. If first or second inputs are numeric they are converted to char. If they are numeric or char arrays they are linearized into a row. If they are cells their contents are converted to char. \matlab+'names'+ output is not supported. This function allows flag strings in third and subsequent inputs to be replaced by numbers, as follows: 1: \matlab+'start'+, 2: \matlab+'split'+, 3: \matlab+'end'+, 4: \matlab+'once'+, 5: \matlab+'tokenExtents'+, 6: \matlab+'tokens'+, 7: \matlab+'match'+ for k = 3:numel(in), if isnumeric(in{k}), in(k) = str(in{k}); end; end; clear str if numel(in)==2, in{3} = 'match'; end if isnumeric(in{1}), in{1}=char(in{1}); end; if isnumeric(in{2}), in{2}=char(in{2}); end + if size(in{1},1)>1, in{1} = in{1}(:).'; end; if size(in{2},1)>1, in{2} = in{2}(:).'; end + if iscell(in{1}), in{1} = cellfun(@char, in{1}, 'UniformOutput', false); end; if iscell(in{2}), in{2} = cellfun(@char, in{2}, 'UniformOutput', false); end; [out{:}] = regexp(in{:}); -YX 3 5 3 4 1 1 1 true true true true if isnumeric(in{1}), in{1}=char(in{1}); end; if isnumeric(in{2}), in{2}=char(in{2}); end; if isnumeric(in{3}), in{3}=char(in{3}); end replace string using regular expression \matlab+regexprep+. If first, second or third inputs are numeric they are converted to char. If they are cells their contents are converted to char +YX 3 5 3 4 1 1 1 true true true true if isnumeric(in{1}), in{1}=char(in{1}); end; if isnumeric(in{2}), in{2}=char(in{2}); end; if isnumeric(in{3}), in{3}=char(in{3}); end replace string using regular expression \matlab+regexprep+. If first, second or third inputs are numeric they are converted to char. If they are numeric or char arrays they are linearized into a row. If they are cells their contents are converted to char + if size(in{1},1)>1, in{1} = in{1}(:).'; end; if size(in{2},1)>1, in{2} = in{2}(:).'; end; if size(in{3},1)>1, in{3} = in{3}(:).'; end; if iscell(in{1}), in{1} = cellfun(@char, in{1}, 'UniformOutput', false); end; if iscell(in{2}), in{2} = cellfun(@char, in{2}, 'UniformOutput', false); end; if iscell(in{3}), in{3} = cellfun(@char, in{3}, 'UniformOutput', false); end [out{:}] = regexprep(in{:}); ZX @@ -922,8 +925,21 @@ Zd 1 2 2 1 1 3 1 true true true true if numel(in)==1 && numel(out)==1, x=in{1}( clear nd sz1 sz2 rm1 rm2 insx1 insx2 end end -e 1 inf 2 1 1 1 1 true true true true if numel(in)>1 reshape array / remove singleton dimensions With $1$ input: \matlab+squeeze+. With more than $1$ input: \matlab+reshape+. If second input is logical, \matlab+size+ is automatically applied to it. If second input is a (non-logical) scalar, a final \matlab+[]+ is implicit. If size specification doesn't contain \matlab+[]+ (explicit or implicit), the first input is padded or truncated if needed; padding is done with \matlab+0+, \matlab+false+, \matlab+char(0)+ or \matlab+{[]}+ according to type of first input. If size specification contains \matlab+[]+ (explicit or implicit), the first input is padded if needed - if islogical(in{2}), in{2} = size(in{2}); end +e 1 inf 2 1 1 1 1 true true true true if numel(in)>1 reshape array / remove singleton dimensions (i) With $1$ input: \matlab+squeeze+. (ii) With more than $1$ input: \matlab+reshape+. If second input is logical, contiguous equal values indicate dimensions that will be collapsed; and a final \matlab+[]+ is implicit. If second input is a (non-logical) scalar, a final \matlab+[]+ is implicit. If size specification doesn't contain \matlab+[]+ (explicit or implicit), the first input is padded or truncated if needed; padding is done with \matlab+0+, \matlab+false+, \matlab+char(0)+ or \matlab+{[]}+ according to type of first input. If size specification contains \matlab+[]+ (explicit or implicit), the first input is padded if needed + if islogical(in{2}) + nd = {size(in{1},1)}; + v = in{2}(1); + for k = 2:numel(in{2}); + if in{2}(k)==v + nd{end} = nd{end}*size(in{1},k); + else + nd{end+1} = size(in{1},k); + v = in{2}(k); + end + end + nd{end+1} = []; + out{1} = reshape(in{1}, nd{:}); + else if numel(in)==2 && isscalar(in{2}), in{3} = []; end if ~any(cellfun(@isempty, in(2:end))) && prod([in{2:end}])>numel(in{1}) if isnumeric(in{1}), in{1} = in{1}(:); in{1}(end+1:prod([in{2:end}])) = 0; @@ -947,6 +963,7 @@ e 1 inf 2 1 1 1 1 true true true true if numel(in)>1 reshape array / remove sin else error('MATL:runtime', 'MATL run-time error: unrecognized type of first input'); end, end out{1} = reshape(in{:}); + end else out{1} = squeeze(in{:}); end diff --git a/help.mat b/help.mat index 8f2325a..72e8c2b 100644 Binary files a/help.mat and b/help.mat differ diff --git a/matl_compile.m b/matl_compile.m index 35d6977..34232aa 100644 --- a/matl_compile.m +++ b/matl_compile.m @@ -338,7 +338,7 @@ fnames = {'num2str' 'im2col' 'spiral' 'unique' 'union' 'intersect' 'setdiff' 'setxor' 'ismember' ... 'triu' 'tril' 'randsample' 'nchoosek' 'vpa' 'sum' 'mean' 'diff' 'mod' 'repelem' 'dec2bin' 'dec2base' ... 'hypergeom' 'disp' 'str2func' 'logical' 'circshift' 'pdist2' 'strsplit' 'max' 'min' 'strncmp' 'round'... - 'datestr' }; + 'datestr' 'regexp' 'regexprep'}; verNumTh = [4 0 0]; % first version in which a modified function is not needed: if (verNum(1)