Mercurial > octave-libgccjit
annotate scripts/miscellaneous/fileparts.m @ 11933:205f10f5cbe8 release-3-0-x
more fixes to fileparts.m tests
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 14 Feb 2009 21:15:23 +0100 |
parents | 8d1427a14f45 |
children |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2003, 2004, 2005, 2006, 2007 John W. Eaton |
4264 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
4264 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
4264 | 18 |
19 ## -*- texinfo -*- | |
4350 | 20 ## @deftypefn {Function File} {[@var{dir}, @var{name}, @var{ext}, @var{ver}] =} fileparts (@var{filename}) |
4264 | 21 ## Return the directory, name, extension, and version components of |
22 ## @var{filename}. | |
5835 | 23 ## @seealso{fullfile} |
4264 | 24 ## @end deftypefn |
25 | |
26 function [directory, name, extension, version] = fileparts (filename) | |
27 | |
28 if (nargin == 1) | |
5443 | 29 if (ischar (filename)) |
11931 | 30 if !( findstr (octave_config_info('canonical_host_type'), 'msvc') || findstr (octave_config_info('canonical_host_type'), 'mingw') ) |
31 ds = rindex (filename, filesep); | |
32 else | |
33 ds = max (rindex (filename, "\\"),rindex (filename, "/")); | |
34 endif | |
4264 | 35 es = rindex (filename, "."); |
5073 | 36 ## These can be the same if they are both 0 (no dir or ext). |
37 if (es <= ds) | |
4683 | 38 es = length(filename)+1; |
39 endif | |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
40 if (ds == 0) |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
41 directory = ""; |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
42 elseif (ds == 1) |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
43 directory = filename(1); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
44 else |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
45 directory = filename(1:ds-1); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
46 endif |
4264 | 47 name = filename(ds+1:es-1); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
48 if (es > 0 && es <= length (filename)) |
5073 | 49 extension = filename(es:end); |
50 else | |
51 extension = ""; | |
52 endif | |
4264 | 53 version = ""; |
54 else | |
4424 | 55 error ("fileparts: expecting filename argument to be a string"); |
4264 | 56 endif |
57 else | |
6046 | 58 print_usage (); |
4264 | 59 endif |
60 | |
61 endfunction | |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 %!test |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
64 %! [d, n, e] = fileparts ("file"); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
65 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, "")); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
66 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 %!test |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
68 %! [d, n, e] = fileparts ("file.ext"); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
69 %! assert (strcmp (d, "") && strcmp (n, "file") && strcmp (e, ".ext")); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
70 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
71 %!test |
11931 | 72 %! [d, n, e] = fileparts ([filesep "file.ext"]); |
73 %! assert (strcmp (d, filesep) && strcmp (n, "file") && strcmp (e, ".ext")); | |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 %!test |
11931 | 76 %! [d, n, e] = fileparts (["dir" filesep "file.ext"]); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
77 %! assert (strcmp (d, "dir") && strcmp (n, "file") && strcmp (e, ".ext")); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
79 %!test |
11932
8d1427a14f45
fix typo in last patch
Jaroslav Hajek <highegg@gmail.com>
parents:
11931
diff
changeset
|
80 %! [d, n, e] = fileparts (["." filesep "file.ext"]); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 %! assert (strcmp (d, ".") && strcmp (n, "file") && strcmp (e, ".ext")); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
82 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
83 %!test |
11931 | 84 %! [d, n, e] = fileparts (["d1" filesep "d2" filesep "file.ext"]); |
11933
205f10f5cbe8
more fixes to fileparts.m tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11932
diff
changeset
|
85 %! assert (strcmp (d, ["d1" filesep "d2"]) && strcmp (n, "file") && strcmp (e, ".ext")); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
86 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 %!test |
11931 | 88 %! [d, n, e] = fileparts ([filesep "d1" filesep "d2" filesep "file.ext"]); |
11933
205f10f5cbe8
more fixes to fileparts.m tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11932
diff
changeset
|
89 %! assert (strcmp (d, [filesep "d1" filesep "d2"]) && strcmp (n, "file") && strcmp (e, ".ext")); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 %!test |
11931 | 92 %! [d, n, e] = fileparts ([filesep ".ext"]); |
11933
205f10f5cbe8
more fixes to fileparts.m tests
Jaroslav Hajek <highegg@gmail.com>
parents:
11932
diff
changeset
|
93 %! assert (strcmp (d, filesep) && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); |
11873
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
95 %!test |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 %! [d, n, e] = fileparts (".ext"); |
e0229beb02c9
fileparts.m: handle "/file" correctly; improve compatibilty
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
97 %! assert (strcmp (d, "") && strcmp (n, char (zeros (1, 0))) && strcmp (e, ".ext")); |