Mercurial > hg > octave-nkf
annotate scripts/strings/validatestring.m @ 12007:dc56a38b5a64 release-3-2-x
var.m: fix typos (thinkos?) in previous change
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 23 Jun 2009 12:57:57 +0200 |
parents | 923c7cb7f13f |
children | be55736a0783 |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 2008, 2009 Bill Denney |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
2 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
3 ## This file is part of Octave. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
4 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
8 ## your option) any later version. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
9 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
13 ## General Public License for more details. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
14 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
18 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}) |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funcname}) |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funcname}, @var{varname}) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@dots{}, @var{position}) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
24 ## Verify that @var{str} is a string or substring of an element of |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
25 ## @var{strarray}. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
26 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
27 ## @var{str} is a character string to be tested, and @var{strarray} is a |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
28 ## cellstr of valid values. @var{validstr} will be the validated form |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
29 ## of @var{str} where validation is defined as @var{str} being a member |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
30 ## or substring of @var{validstr}. If @var{str} is a substring of |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
31 ## @var{validstr} and there are multiple matches, the shortest match |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
32 ## will be returned if all matches are substrings of each other, and an |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
33 ## error will be raised if the matches are not substrings of each other. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
34 ## |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
35 ## All comparisons are case insensitive. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
36 ## @seealso{strcmp, strcmpi} |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
37 ## @end deftypefn |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
38 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
39 ## Author: Bill Denney <bill@denney.ws> |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
40 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
41 function str = validatestring (str, strarray, varargin) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
42 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
43 if (nargin < 2 || nargin > 5) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
44 print_usage (); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
45 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
46 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
47 ## set the defaults |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
48 funcname = ""; |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
49 varname = ""; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
50 position = 0; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
51 ## set the actual values |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
52 if (! isempty (varargin)) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
53 if (isnumeric (varargin{end})) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
54 position = varargin{end}; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
55 varargin(end) = []; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
56 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
57 endif |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
58 funcnameset = false; |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
59 varnameset = false; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
60 for i = 1:numel (varargin) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
61 if (ischar (varargin{i})) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
62 if (varnameset) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
63 error ("validatestring: invalid number of character inputs: %d", |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
64 numel (varargin)); |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
65 elseif (funcnameset) |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
66 varname = varargin{i}; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
67 varnameset = true; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
68 else |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
69 funcname = varargin{i}; |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
70 funcnameset = true; |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
71 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
72 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
73 endfor |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
74 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
75 ## Check the inputs |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
76 if (! ischar (str)) |
8664 | 77 error ("validatestring: str must be a character string"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
78 elseif (rows (str) != 1) |
8664 | 79 error ("validatestring: str must have only one row"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
80 elseif (! iscellstr (strarray)) |
8664 | 81 error ("validatestring: strarray must be a cellstr"); |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
82 elseif (! ischar (funcname)) |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
83 error ("validatestring: funcname must be a character string"); |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
84 elseif (! isempty (funcname) && (rows (funcname) != 1)) |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
85 error ("validatestring: funcname must be exactly one row"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
86 elseif (! ischar (varname)) |
8664 | 87 error ("validatestring: varname must be a character string"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
88 elseif (! isempty (varname) && (rows (varname) != 1)) |
8664 | 89 error ("validatestring: varname must be exactly one row"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
90 elseif (position < 0) |
8664 | 91 error ("validatestring: position must be >= 0"); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
92 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
93 |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
94 ## make the part of the error that will use funcname, varname, and |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
95 ## position |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
96 errstr = ""; |
9209
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
97 if (! isempty (funcname)) |
923c7cb7f13f
Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
98 errstr = sprintf ("Function: %s ", funcname); |
7658
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
99 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
100 if (! isempty (varname)) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
101 errstr = sprintf ("%sVariable: %s ", errstr, varname); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
102 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
103 if (position > 0) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
104 errstr = sprintf ("%sArgument position %d ", errstr, position); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
105 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
106 if (! isempty (errstr)) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
107 errstr(end:end+1) = ":\n"; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
108 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
109 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
110 matches = strncmpi (str, strarray(:), numel (str)); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
111 nmatches = sum (matches); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
112 if (nmatches == 1) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
113 str = strarray{matches}; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
114 elseif (nmatches == 0) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
115 error ("validatestring: %s%s does not match any of\n%s", errstr, str, |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
116 sprintf ("%s, ", strarray{:})(1:end-1)); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
117 else |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
118 ## are the matches a substring of each other, if so, choose the |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
119 ## shortest. If not, raise an error. |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
120 match_idx = find (matches); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
121 match_l = cellfun (@length, strarray(match_idx)); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
122 longest_idx = find (match_l == max (match_l), 1); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
123 shortest_idx = find (match_l == min (match_l), 1); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
124 longest = strarray(match_idx)(longest_idx); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
125 for i = 1:numel(match_idx) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
126 currentmatch = strarray(match_idx(i)); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
127 if (! strncmpi (longest, currentmatch, length(currentmatch))) |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
128 error ("validatestring: %smultiple unique matches were found for %s:\n%s", |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
129 errstr, sprintf ("%s, ", strarray(match_idx))(1:end-2)); |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
130 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
131 endfor |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
132 str = strarray{shortest_idx}; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
133 endif |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
134 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
135 endfunction |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
136 |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
137 ## Tests |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
138 %!shared strarray |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
139 %! strarray = {"octave" "Oct" "octopus" "octaves"}; |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
140 %!assert (validatestring ("octave", strarray), "octave") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
141 %!assert (validatestring ("oct", strarray), "Oct") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
142 %!assert (validatestring ("octave", strarray), "octave") |
1ce6460aebdf
nargoutchk.m, validatestring.m, addtodate.m: new functions
bill@denney.ws
parents:
diff
changeset
|
143 %!assert (validatestring ("octav", strarray), "octave") |