Mercurial > hg > octave-avbm
changeset 7288:1885f4c7e4b3
[project @ 2007-12-11 17:19:44 by jwe]
author | jwe |
---|---|
date | Tue, 11 Dec 2007 17:19:44 +0000 |
parents | 3f29467c1667 |
children | e5055ed23f52 |
files | scripts/ChangeLog scripts/miscellaneous/fullfile.m |
diffstat | 2 files changed, 33 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,7 @@ 2007-12-11 David Bateman <dbateman@free.fr> + * miscelleaneous/fullfile.m: Ignore empty arguments. + * sparse/spstats.m: Drop argument to Fsparse to force mutation. * statistics/base/mode.m: Ditto.
--- a/scripts/miscellaneous/fullfile.m +++ b/scripts/miscellaneous/fullfile.m @@ -25,25 +25,42 @@ function filename = fullfile (varargin) if (nargin > 0) - filename = varargin{1}; - if (length (filename) < 1) - filename = "."; - endif - if (strcmp (filename(end), filesep)) - filename(end) = ""; - endif - for i = 2:nargin + filename = ""; + for first = 1:nargin + tmp = varargin{first}; + if (! isempty (tmp)) + filename = tmp; + break; + endif + endfor + for i = first+1:nargin tmp = varargin{i}; - if (strcmp (tmp(1), filesep)) - tmp(1) = ""; + if (! isempty (tmp)) + if (strcmp (tmp(1), filesep)) + tmp(1) = ""; + endif + if (i < nargin && strcmp (tmp(end), filesep)) + tmp(end) = ""; + endif + filename = strcat (filename, filesep, tmp); endif - if (i < nargin && strcmp (tmp(end), filesep)) - tmp(end) = ""; - endif - filename = strcat (filename, filesep, tmp); endfor else print_usage (); endif endfunction + +%!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"))