Mercurial > hg > octave-kai
changeset 7514:4f6a73fd8df9
fullfile: improve handling of args ending with filesep
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Feb 2008 13:47:38 -0500 |
parents | 05eb3486f650 |
children | f3c00dc0912b |
files | scripts/ChangeLog scripts/miscellaneous/fullfile.m |
diffstat | 2 files changed, 47 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,8 @@ 2008-02-22 John W. Eaton <jwe@octave.org> + * miscellaneous/fullfile.m: Improve handling of empty args and + args ending with filesep. + * control/base/__stepimp__.m: Don't use subplot for just one plot. 2008-02-21 John W. Eaton <jwe@octave.org>
--- a/scripts/miscellaneous/fullfile.m +++ b/scripts/miscellaneous/fullfile.m @@ -25,42 +25,56 @@ function filename = fullfile (varargin) if (nargin > 0) - filename = ""; - for first = 1:nargin - tmp = varargin{first}; - if (! isempty (tmp)) - filename = tmp; - break; + ## Discard all empty arguments + varargin(cellfun (@isempty, varargin)) = []; + nargs = numel (varargin); + if (nargs > 1) + filename = varargin{1}; + if (strcmp (filename(end), filesep)) + filename(end) = ""; endif - endfor - for i = first+1:nargin - tmp = varargin{i}; - if (! isempty (tmp)) - if (strcmp (tmp(1), filesep)) - tmp(1) = ""; + for i = 2:nargs + tmp = varargin{i}; + if (i < nargs && strcmp (tmp(end), filesep)) + tmp(end) = ""; + elseif (i == nargs && strcmp (tmp, filesep)) + tmp = ""; endif - if (i < nargin && strcmp (tmp(end), filesep)) - tmp(end) = ""; - endif - filename = strcat (filename, filesep, tmp); - endif - endfor + filename = strcat (filename, filesep, tmp); + endfor + elseif (nargs == 1) + filename = varargin{1}; + else + filename = ""; + endif else print_usage (); endif endfunction +%!shared fs, fsx, xfs, fsxfs, xfsy +%! fs = filesep (); +%! fsx = strcat (fs, "x"); +%! xfs = strcat ("x", fs); +%! fsxfs = strcat (fs, "x", fs); +%! xfsy = strcat ("x", fs, "y"); %!assert (fullfile (""), "") -%!assert (fullfile (filesep ()), filesep ()) -%!assert (fullfile ("", filesep ()), filesep ()) -%!assert (fullfile (filesep (), ""), filesep ()) -%!assert (fullfile ("", filesep ()), filesep ()) -%!assert (fullfile ("foo"), "foo") -%!assert (fullfile ("", "foo"), "foo") -%!assert (fullfile ("foo", ""), "foo") -%!assert (fullfile ("", "foo", ""), "foo") -%!assert (fullfile ("foo", "bar"), strcat ("foo", filesep (), "bar")) -%!assert (fullfile ("foo", "", "bar"), strcat ("foo", filesep (), "bar")) -%!assert (fullfile ("foo", "", "bar", ""), strcat ("foo", filesep (), "bar")) -%!assert (fullfile ("", "foo", "", "bar", ""), strcat ("foo", filesep (), "bar")) +%!assert (fullfile (fs), fs) +%!assert (fullfile ("", fs), fs) +%!assert (fullfile (fs, ""), fs) +%!assert (fullfile ("", fs), fs) +%!assert (fullfile ("x"), "x") +%!assert (fullfile ("", "x"), "x") +%!assert (fullfile ("x", ""), "x") +%!assert (fullfile ("", "x", ""), "x") +%!assert (fullfile ("x", "y"), xfsy) +%!assert (fullfile ("x", "", "y"), xfsy) +%!assert (fullfile ("x", "", "y", ""), xfsy) +%!assert (fullfile ("", "x", "", "y", ""), xfsy) +%!assert (fullfile (fs), fs) +%!assert (fullfile (fs, fs), fs) +%!assert (fullfile (fs, "x"), fsx) +%!assert (fullfile (fs, xfs), fsxfs) +%!assert (fullfile (fsx, fs), fsxfs) +%!assert (fullfile (fs, "x", fs), fsxfs)