comparison src/strfns.cc @ 5862:2b35a7fe9302

[project @ 2006-06-20 04:31:56 by jwe]
author jwe
date Tue, 20 Jun 2006 04:31:56 +0000
parents 080c08b192d8
children a65b51ed388c
comparison
equal deleted inserted replaced
5861:2a6cb4ed8f1e 5862:2b35a7fe9302
227 str = args(1).all_strings (); 227 str = args(1).all_strings ();
228 r = args(1).rows (); 228 r = args(1).rows ();
229 cell = args(0).cell_value (); 229 cell = args(0).cell_value ();
230 } 230 }
231 231
232 if (r == 1) 232 if (r == 0 || r == 1)
233 { 233 {
234 // Broadcast the string. 234 // Broadcast the string.
235 235
236 boolNDArray output (cell.dimensions); 236 boolNDArray output (cell.dimensions);
237
238 std::string s = r == 0 ? std::string () : str[0];
237 239
238 for (int i = 0; i < cell.length (); i++) 240 for (int i = 0; i < cell.length (); i++)
239 if (cell(i).is_string ()) 241 if (cell(i).is_string ())
240 output(i) = (cell(i).string_value () == str[0]); 242 output(i) = (cell(i).string_value () == s);
241 else 243 else
242 output(i) = false; 244 output(i) = false;
243 245
244 retval = output; 246 retval = output;
245 } 247 }
371 else 373 else
372 print_usage (); 374 print_usage ();
373 375
374 return retval; 376 return retval;
375 } 377 }
378
379 /*
380 %!shared x
381 %! x = char (zeros (0, 2));
382 %!assert (strcmp ('', x) == false);
383 %!assert (strcmp (x, '') == false);
384 %!assert (strcmp (x, x) == true);
385 %!assert (strcmp ({''}, x) == false);
386 %!assert (strcmp ({x}, '') == false);
387 %!assert (strcmp ({x}, x) == true);
388 %!assert (strcmp ('', {x}) == false);
389 %!assert (strcmp (x, {''}) == false);
390 %!assert (strcmp (x, {x}) == true);
391 %!assert (all (strcmp ({x; x}, '') == [false; false]));
392 %!assert (all (strcmp ({x; x}, {''}) == [false; false]));
393 %!assert (all (strcmp ('', {x; x}) == [false; false]));
394 %!assert (all (strcmp ({''}, {x; x}) == [false; false]));
395 %!assert (strcmp ({'foo'}, x) == false);
396 %!assert (strcmp ({'foo'}, 'foo') == true);
397 %!assert (strcmp ({'foo'}, x) == false);
398 %!assert (strcmp (x, {'foo'}) == false);
399 %!assert (strcmp ('foo', {'foo'}) == true);
400 %!assert (strcmp (x, {'foo'}) == false);
401 %!shared y
402 %! y = char (zeros (2, 0));
403 %!assert (strcmp ('', y) == false);
404 %!assert (strcmp (y, '') == false);
405 %!assert (strcmp (y, y) == true);
406 %!assert (all (strcmp ({''}, y) == [true; true]));
407 %!assert (strcmp ({y}, '') == true);
408 %!assert (all (strcmp ({y}, y) == [true; true]));
409 %!assert (all (strcmp ('', {y}) == [true; true]));
410 %!assert (all (strcmp (y, {''}) == [true; true]));
411 %!assert (all (strcmp (y, {y}) == [true; true]));
412 %!assert (all (strcmp ({y; y}, '') == [false; false]));
413 %!assert (all (strcmp ({y; y}, {''}) == [false; false]));
414 %!assert (all (strcmp ('', {y; y}) == [false; false]));
415 %!assert (all (strcmp ({''}, {y; y}) == [false; false]));
416 %!assert (all (strcmp ({'foo'}, y) == [false; false]));
417 %!assert (all (strcmp ({'foo'}, y) == [false; false]));
418 %!assert (all (strcmp (y, {'foo'}) == [false; false]));
419 %!assert (all (strcmp (y, {'foo'}) == [false; false]));
420 */
376 421
377 DEFUN (list_in_columns, args, , 422 DEFUN (list_in_columns, args, ,
378 "-*- texinfo -*-\n\ 423 "-*- texinfo -*-\n\
379 @deftypefn {Built-in Function} {} list_in_columns (@var{arg}, @var{width})\n\ 424 @deftypefn {Built-in Function} {} list_in_columns (@var{arg}, @var{width})\n\
380 Return a string containing the elements of @var{arg} listed in\n\ 425 Return a string containing the elements of @var{arg} listed in\n\