From bug-request at octave dot org Fri Apr 14 10:10:44 2006 Subject: strcmpi doesn't check input types From: "John W. Eaton" To: Bill Denney Cc: bugs at octave dot org Date: Fri, 14 Apr 2006 11:10:32 -0400 On 14-Apr-2006, Bill Denney wrote: | Here is a patch that makes strcmpi check the type of its input arguements. | | Bill | | scripts/Changelog | | 2006-04-14 Bill Denney | | * strings/strcmpi.m: input checking | | -- | "The plural of spouse is spice." -- Christopher Morely | Index: strcmpi.m | =================================================================== | RCS file: /cvs/octave/scripts/strings/strcmpi.m,v | retrieving revision 1.6 | diff -u -r1.6 strcmpi.m | --- strcmpi.m 16 Mar 2006 04:09:07 -0000 1.6 | +++ strcmpi.m 14 Apr 2006 14:47:00 -0000 | at @ -42,7 +42,11 @@ | if (nargin == 2) | ## Note that we don't use tolower here because we need to be able to | ## handle cell arrays of strings. | - retval = strcmp (lower (s1), lower (s2)); | + if ((ischar(s1) || iscellstr(s1)) && (ischar(s2) || iscellstr(s2))) | + retval = strcmp (lower (s1), lower (s2)); | + else | + error("strcmpi: s1 and s2 must be char or cellstr"); | + endif | else | usage ("strcmpi (s1, s2)"); | endif I agree that the current behavior is not right, but an error would make the behavior of strcmpi different from strcmp, so I think it should just return 0 if the arguments are not the right type. jwe ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------