# HG changeset patch # User Rik # Date 1320164920 25200 # Node ID 73b2b3ca652411c46337439118c99a3250472fd5 # Parent f5535b401c83c49f3f888993c397f6da59abd859 strsplit.m: Use S instead of P to denote string argument (Bug #"a diff -r f5535b401c83 -r 73b2b3ca6524 scripts/strings/strsplit.m --- a/scripts/strings/strsplit.m Sun Oct 30 16:59:03 2011 -0700 +++ b/scripts/strings/strsplit.m Tue Nov 01 09:28:40 2011 -0700 @@ -17,7 +17,7 @@ ## . ## -*- texinfo -*- -## @deftypefn {Function File} {[@var{cstr}] =} strsplit (@var{p}, @var{sep}, @var{strip_empty}) +## @deftypefn {Function File} {[@var{cstr}] =} strsplit (@var{s}, @var{sep}, @var{strip_empty}) ## Split a string using one or more delimiters and return a cell ## array of strings. Consecutive delimiters and delimiters at ## boundaries result in empty strings, unless @var{strip_empty} is true. @@ -49,51 +49,51 @@ ## @seealso{strtok} ## @end deftypefn -function s = strsplit (p, sep, strip_empty = false) +function cstr = strsplit (s, sep, strip_empty = false) if (nargin < 2 || nargin > 3) print_usage (); - elseif (! ischar (p) || ! ischar (sep)) - error ("strsplit: P and SEP must be string values"); + elseif (! ischar (s) || ! ischar (sep)) + error ("strsplit: S and SEP must be string values"); elseif (! isscalar (strip_empty)) error ("strsplit: STRIP_EMPTY must be a scalar value"); endif - if (isempty (p)) - s = cell (size (p)); + if (isempty (s)) + cstr = cell (size (s)); else - if (rows (p) > 1) + if (rows (s) > 1) ## For 2-D arrays, add separator character at line boundaries ## and transform to single string - p(:, end+1) = sep(1); - p = reshape (p.', 1, numel (p)); - p(end) = []; + s(:, end+1) = sep(1); + s = reshape (s.', 1, numel (s)); + s(end) = []; endif - ## Split p according to delimiter + ## Split s according to delimiter if (isscalar (sep)) ## Single separator - idx = find (p == sep); + idx = find (s == sep); else ## Multiple separators - idx = strchr (p, sep); + idx = strchr (s, sep); endif ## Get substring lengths. if (isempty (idx)) - strlens = length (p); + strlens = length (s); else - strlens = [idx(1)-1, diff(idx)-1, numel(p)-idx(end)]; + strlens = [idx(1)-1, diff(idx)-1, numel(s)-idx(end)]; endif ## Remove separators. - p(idx) = []; + s(idx) = []; if (strip_empty) ## Omit zero lengths. strlens = strlens(strlens != 0); endif ## Convert! - s = mat2cell (p, 1, strlens); + cstr = mat2cell (s, 1, strlens); endif endfunction @@ -110,7 +110,7 @@ %!error strsplit () %!error strsplit ("abc") %!error strsplit ("abc", "b", true, 4) -%!error

strsplit (123, "b") -%!error

strsplit ("abc", 1) +%!error strsplit (123, "b") +%!error strsplit ("abc", 1) %!error strsplit ("abc", "def", ones(3,3))