comparison scripts/strings/validatestring.m @ 9209:923c7cb7f13f

Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction. spellchecked all .txi and .texi files.
author Rik <rdrider0-list@yahoo.com>
date Sun, 17 May 2009 12:18:06 -0700
parents eb63fbe60fab
children be55736a0783
comparison
equal deleted inserted replaced
9208:cb163402bf79 9209:923c7cb7f13f
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}) 20 ## @deftypefn {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray})
21 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funname}) 21 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funcname})
22 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funname}, @var{varname}) 22 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@var{str}, @var{strarray}, @var{funcname}, @var{varname})
23 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@dots{}, @var{position}) 23 ## @deftypefnx {Function File} {@var{validstr} =} validatestring (@dots{}, @var{position})
24 ## Verify that @var{str} is a string or substring of an element of 24 ## Verify that @var{str} is a string or substring of an element of
25 ## @var{strarray}. 25 ## @var{strarray}.
26 ## 26 ##
27 ## @var{str} is a character string to be tested, and @var{strarray} is a 27 ## @var{str} is a character string to be tested, and @var{strarray} is a
43 if (nargin < 2 || nargin > 5) 43 if (nargin < 2 || nargin > 5)
44 print_usage (); 44 print_usage ();
45 endif 45 endif
46 46
47 ## set the defaults 47 ## set the defaults
48 funname = ""; 48 funcname = "";
49 varname = ""; 49 varname = "";
50 position = 0; 50 position = 0;
51 ## set the actual values 51 ## set the actual values
52 if (! isempty (varargin)) 52 if (! isempty (varargin))
53 if (isnumeric (varargin{end})) 53 if (isnumeric (varargin{end}))
54 position = varargin{end}; 54 position = varargin{end};
55 varargin(end) = []; 55 varargin(end) = [];
56 endif 56 endif
57 endif 57 endif
58 funnameset = false; 58 funcnameset = false;
59 varnameset = false; 59 varnameset = false;
60 for i = 1:numel (varargin) 60 for i = 1:numel (varargin)
61 if (ischar (varargin{i})) 61 if (ischar (varargin{i}))
62 if (varnameset) 62 if (varnameset)
63 error ("validatestring: invalid number of character inputs: %d", 63 error ("validatestring: invalid number of character inputs: %d",
64 numel (varargin)); 64 numel (varargin));
65 elseif (funnameset) 65 elseif (funcnameset)
66 varname = varargin{i}; 66 varname = varargin{i};
67 varnameset = true; 67 varnameset = true;
68 else 68 else
69 funname = varargin{i}; 69 funcname = varargin{i};
70 funnameset = true; 70 funcnameset = true;
71 endif 71 endif
72 endif 72 endif
73 endfor 73 endfor
74 74
75 ## Check the inputs 75 ## Check the inputs
77 error ("validatestring: str must be a character string"); 77 error ("validatestring: str must be a character string");
78 elseif (rows (str) != 1) 78 elseif (rows (str) != 1)
79 error ("validatestring: str must have only one row"); 79 error ("validatestring: str must have only one row");
80 elseif (! iscellstr (strarray)) 80 elseif (! iscellstr (strarray))
81 error ("validatestring: strarray must be a cellstr"); 81 error ("validatestring: strarray must be a cellstr");
82 elseif (! ischar (funname)) 82 elseif (! ischar (funcname))
83 error ("validatestring: funname must be a character string"); 83 error ("validatestring: funcname must be a character string");
84 elseif (! isempty (funname) && (rows (funname) != 1)) 84 elseif (! isempty (funcname) && (rows (funcname) != 1))
85 error ("validatestring: funname must be exactly one row"); 85 error ("validatestring: funcname must be exactly one row");
86 elseif (! ischar (varname)) 86 elseif (! ischar (varname))
87 error ("validatestring: varname must be a character string"); 87 error ("validatestring: varname must be a character string");
88 elseif (! isempty (varname) && (rows (varname) != 1)) 88 elseif (! isempty (varname) && (rows (varname) != 1))
89 error ("validatestring: varname must be exactly one row"); 89 error ("validatestring: varname must be exactly one row");
90 elseif (position < 0) 90 elseif (position < 0)
91 error ("validatestring: position must be >= 0"); 91 error ("validatestring: position must be >= 0");
92 endif 92 endif
93 93
94 ## make the part of the error that will use funname, varname, and 94 ## make the part of the error that will use funcname, varname, and
95 ## position 95 ## position
96 errstr = ""; 96 errstr = "";
97 if (! isempty (funname)) 97 if (! isempty (funcname))
98 errstr = sprintf ("Function: %s ", funname); 98 errstr = sprintf ("Function: %s ", funcname);
99 endif 99 endif
100 if (! isempty (varname)) 100 if (! isempty (varname))
101 errstr = sprintf ("%sVariable: %s ", errstr, varname); 101 errstr = sprintf ("%sVariable: %s ", errstr, varname);
102 endif 102 endif
103 if (position > 0) 103 if (position > 0)