Mercurial > hg > octave-terminal
changeset 8884:579de77acd90
strsplit.m: style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 27 Feb 2009 03:31:41 -0500 |
parents | 7de0992eb123 |
children | 47fb59095191 |
files | scripts/ChangeLog scripts/strings/strsplit.m src/symtab.h |
diffstat | 3 files changed, 21 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2009-02-27 John W. Eaton <jwe@octave.org> + + * strings/strsplit.m: Style fixes. + 2009-02-27 Jaroslav Hajek <highegg@gmail.com> * strings/strsplit.m: Check also nargin.
--- a/scripts/strings/strsplit.m +++ b/scripts/strings/strsplit.m @@ -16,45 +16,48 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {[@var{s}] =} strsplit (@var{p}, @var{sep}, @var{strip_empty}) -## Splits a single string using one or more delimiters. -## The result is returned as a cell array of strings. Consecutive delimiters -## and delimiters at boundaries result in empty strings, unless @var{strip_empty} is true. +## Split a single 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. ## The default value of @var{strip_empty} is false. +## @seealso{strtok} ## @end deftypefn function s = strsplit (p, sep, strip_empty = false) - if (nargin < 2 || nargin > 3 || ! ischar (p) || rows (p) > 1 \ - || ! ischar (sep) || ! islogical (strip_empty)) + + if (nargin < 2 || nargin > 3 || ! ischar (p) || rows (p) > 1 + || ! ischar (sep) || ! islogical (strip_empty)) print_usage (); endif if (isempty (p)) s = cell (size (p)); else - ## split p according to delimiter. + ## Split p according to delimiter. if (isscalar (sep)) - ## single separator + ## Single separator. idx = find (p == sep); else - ## multiple separators + ## Multiple separators. idx = strchr (p, sep); endif - ## get substring sizes. + ## Get substring sizes. if (isempty (idx)) sizes = numel (p); else sizes = [idx(1)-1, diff(idx)-1, numel(p)-idx(end)]; endif - ## remove separators. + ## Remove separators. p(idx) = []; if (strip_empty) - ## omit zero lengths. + ## Omit zero lengths. sizes = sizes (sizes != 0); endif - ## convert! + ## Convert! s = mat2cell (p, 1, sizes); endif + endfunction %!assert (all (strcmp (strsplit ("road to hell", " "), {"road", "to", "hell"})))