From: <car...@us...> - 2012-03-15 22:39:16
|
Revision: 9912 http://octave.svn.sourceforge.net/octave/?rev=9912&view=rev Author: carandraug Date: 2012-03-15 22:39:10 +0000 (Thu, 15 Mar 2012) Log Message: ----------- cstrcmp: aesthetics only Modified Paths: -------------- trunk/octave-forge/main/strings/inst/cstrcmp.m Modified: trunk/octave-forge/main/strings/inst/cstrcmp.m =================================================================== --- trunk/octave-forge/main/strings/inst/cstrcmp.m 2012-03-15 22:24:43 UTC (rev 9911) +++ trunk/octave-forge/main/strings/inst/cstrcmp.m 2012-03-15 22:39:10 UTC (rev 9912) @@ -31,54 +31,51 @@ ## @end deftypefn ## @seealso {strcmp} -function rval=cstrcmp(s1,s2) +function rval = cstrcmp (s1, s2) + if nargin < 2 print_usage(); - end - v1=iscell(s1); - v2=iscell(s2); + endif + v1 = iscell (s1); + v2 = iscell (s2); if (v1+v2) == 2; - error(' Only one argument can be a cell-array; see help cstrcmp;'); - end + error("only one argument can be a cell-array"); + endif if (v1+v2) == 0 - rval=do_cstrcmp(s1,s2); - return; - end + rval = do_cstrcmp (s1, s2); + return + endif if(v2) [s1, s2] = deal (s1, s2); - end + endif - L=length(s1); - rval=zeros(1,L); + L = length (s1); + rval = zeros (1, L); for idx=1:L - rval(idx)=do_cstrcmp(s1{idx},s2); - end + rval(idx )= do_cstrcmp (s1{idx}, s2); + endfor +endfunction - return; -end -%! +function v = do_cstrcmp (s1, s2) + L2 = length (s2); + L1 = length (s1); + L = min (L1, L2); + for idx=1:L + p = s1(idx); + q = s2(idx); + if (p != q) + v = sign (p-q); + return + endif + endfor + v = sign (L1-L2); +endfunction + %!assert(cstrcmp("hello","hello"),0,0) %!assert(cstrcmp('marry','marie'),+1,0) %!assert(cstrcmp('Matlab','Octave'),-1,0) %!assert(cstrcmp('Matlab',{'Octave','Scilab','Lush','Yorick'}),[-1,-1,+1,-1],[]) %!assert(cstrcmp({'Octave','Scilab','Lush','Yorick'},'Matlab'),[+1,+1,-1,+1],[]) -%! - -function v=do_cstrcmp(s1,s2) - L2=length(s2); - L1=length(s1); - L=min(L1,L2); - for idx=1:L - p=s1(idx); - q=s2(idx); - if ( p ~= q ) - v=sign(p-q); - return - end - end - v=sign(L1-L2); - return -end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |