Mercurial > hg > octave-lyh
changeset 5862:2b35a7fe9302
[project @ 2006-06-20 04:31:56 by jwe]
author | jwe |
---|---|
date | Tue, 20 Jun 2006 04:31:56 +0000 |
parents | 2a6cb4ed8f1e |
children | 4c16f3104aa5 |
files | src/ChangeLog src/ov-re-mat.cc src/strfns.cc |
diffstat | 3 files changed, 85 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2006-06-20 John W. Eaton <jwe@octave.org> + + * ov-re-mat.cc (octave_matrix::convert_to_str_internal): + Don't lose empty dimensions on conversion to char. + + * strfns.cc (Fstrcmp): Handle comparison of cellstr and empty string. + 2006-06-16 John W. Eaton <jwe@octave.org> * parse.y (%union): New type, anon_fcn_handle_type.
--- a/src/ov-re-mat.cc +++ b/src/ov-re-mat.cc @@ -201,54 +201,46 @@ { octave_value retval; dim_vector dv = dims (); - int nel = dv.numel (); + octave_idx_type nel = dv.numel (); + + charNDArray chm (dv); - if (nel == 0) - { - char s = '\0'; - retval = octave_value (&s, type); - } - else + bool warned = false; + + for (octave_idx_type i = 0; i < nel; i++) { - charNDArray chm (dv); - - bool warned = false; + OCTAVE_QUIT; + + double d = matrix (i); - for (octave_idx_type i = 0; i < nel; i++) + if (xisnan (d)) + { + ::error ("invalid conversion from NaN to character"); + return retval; + } + else { - OCTAVE_QUIT; + int ival = NINT (d); - double d = matrix (i); + if (ival < 0 || ival > UCHAR_MAX) + { + // FIXME -- is there something + // better we could do? - if (xisnan (d)) - { - ::error ("invalid conversion from NaN to character"); - return retval; + ival = 0; + + if (! warned) + { + ::warning ("range error for conversion to character value"); + warned = true; + } } - else - { - int ival = NINT (d); - - if (ival < 0 || ival > UCHAR_MAX) - { - // FIXME -- is there something - // better we could do? - - ival = 0; - if (! warned) - { - ::warning ("range error for conversion to character value"); - warned = true; - } - } + chm (i) = static_cast<char> (ival); + } + } - chm (i) = static_cast<char> (ival); - } - } - - retval = octave_value (chm, true, type); - } + retval = octave_value (chm, true, type); return retval; }
--- a/src/strfns.cc +++ b/src/strfns.cc @@ -229,15 +229,17 @@ cell = args(0).cell_value (); } - if (r == 1) + if (r == 0 || r == 1) { // Broadcast the string. boolNDArray output (cell.dimensions); + std::string s = r == 0 ? std::string () : str[0]; + for (int i = 0; i < cell.length (); i++) if (cell(i).is_string ()) - output(i) = (cell(i).string_value () == str[0]); + output(i) = (cell(i).string_value () == s); else output(i) = false; @@ -374,6 +376,49 @@ return retval; } +/* +%!shared x +%! x = char (zeros (0, 2)); +%!assert (strcmp ('', x) == false); +%!assert (strcmp (x, '') == false); +%!assert (strcmp (x, x) == true); +%!assert (strcmp ({''}, x) == false); +%!assert (strcmp ({x}, '') == false); +%!assert (strcmp ({x}, x) == true); +%!assert (strcmp ('', {x}) == false); +%!assert (strcmp (x, {''}) == false); +%!assert (strcmp (x, {x}) == true); +%!assert (all (strcmp ({x; x}, '') == [false; false])); +%!assert (all (strcmp ({x; x}, {''}) == [false; false])); +%!assert (all (strcmp ('', {x; x}) == [false; false])); +%!assert (all (strcmp ({''}, {x; x}) == [false; false])); +%!assert (strcmp ({'foo'}, x) == false); +%!assert (strcmp ({'foo'}, 'foo') == true); +%!assert (strcmp ({'foo'}, x) == false); +%!assert (strcmp (x, {'foo'}) == false); +%!assert (strcmp ('foo', {'foo'}) == true); +%!assert (strcmp (x, {'foo'}) == false); +%!shared y +%! y = char (zeros (2, 0)); +%!assert (strcmp ('', y) == false); +%!assert (strcmp (y, '') == false); +%!assert (strcmp (y, y) == true); +%!assert (all (strcmp ({''}, y) == [true; true])); +%!assert (strcmp ({y}, '') == true); +%!assert (all (strcmp ({y}, y) == [true; true])); +%!assert (all (strcmp ('', {y}) == [true; true])); +%!assert (all (strcmp (y, {''}) == [true; true])); +%!assert (all (strcmp (y, {y}) == [true; true])); +%!assert (all (strcmp ({y; y}, '') == [false; false])); +%!assert (all (strcmp ({y; y}, {''}) == [false; false])); +%!assert (all (strcmp ('', {y; y}) == [false; false])); +%!assert (all (strcmp ({''}, {y; y}) == [false; false])); +%!assert (all (strcmp ({'foo'}, y) == [false; false])); +%!assert (all (strcmp ({'foo'}, y) == [false; false])); +%!assert (all (strcmp (y, {'foo'}) == [false; false])); +%!assert (all (strcmp (y, {'foo'}) == [false; false])); +*/ + DEFUN (list_in_columns, args, , "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {} list_in_columns (@var{arg}, @var{width})\n\