# HG changeset patch # User John W. Eaton # Date 1231821692 18000 # Node ID 5451f7460ea6b81d9e8cc40291c1672f8569119b # Parent 02de6775f1fecbca5429c8a653937ea7af55ec8f strfns.cc (Fstrcmp, Fstrncmp): initialize all elements of output with constructor arg diff -r 02de6775f1fe -r 5451f7460ea6 src/ChangeLog --- a/src/ChangeLog Mon Jan 12 19:03:33 2009 -0500 +++ b/src/ChangeLog Mon Jan 12 23:41:32 2009 -0500 @@ -1,3 +1,12 @@ +2009-01-12 John W. Eaton + + * strfns.cc (Fstrcmp, Fstrncmp): Simplify by initializing all + elements of output to false with constructor argument. + +2009-01-12 Thorsten Meyer + + * strfns.cc (Fstrncmp): New test. + 2009-01-12 John W. Eaton * pt-stmt.h (tree_statement::is_null_statement): New function. diff -r 02de6775f1fe -r 5451f7460ea6 src/strfns.cc --- a/src/strfns.cc Mon Jan 12 19:03:33 2009 -0500 +++ b/src/strfns.cc Mon Jan 12 23:41:32 2009 -0500 @@ -395,7 +395,7 @@ { // Broadcast the string. - boolNDArray output (cell.dimensions); + boolNDArray output (cell.dimensions, false); std::string s = r == 0 ? std::string () : str[0]; @@ -403,8 +403,6 @@ { if (cell(i).is_string ()) output(i) = (cell(i).string_value () == s); - else - output(i) = false; } retval = output; @@ -416,7 +414,7 @@ // Broadcast the cell. const dim_vector dv (r, 1); - boolNDArray output (dv); + boolNDArray output (dv, false); if (cell(0).is_string ()) { @@ -425,11 +423,6 @@ for (int i = 0; i < r; i++) output(i) = (str[i] == str2); } - else - { - for (int i = 0; i < r; i++) - output(i) = false; - } retval = output; } @@ -437,7 +430,7 @@ { // Must match in all dimensions. - boolNDArray output (cell.dimensions); + boolNDArray output (cell.dimensions, false); if (cell.length () == r) { @@ -445,8 +438,6 @@ { if (cell(i).is_string ()) output(i) = (str[i] == cell(i).string_value ()); - else - output(i) = false; } retval = output; @@ -483,18 +474,13 @@ const dim_vector size1 = cell1.dimensions; const dim_vector size2 = cell2.dimensions; - boolNDArray output (size1); + boolNDArray output (size1, false); if (r2 == 1) { // Broadcast cell2. - if (! cell2(0).is_string ()) - { - for (int i = 0; i < r1; i++) - output(i) = false; - } - else + if (cell2(0).is_string ()) { const std::string str2 = cell2(0).string_value (); @@ -505,8 +491,6 @@ const std::string str1 = cell1(i).string_value (); output(i) = (str1 == str2); } - else - output(i) = false; } } } @@ -526,8 +510,6 @@ const std::string str2 = cell2(i).string_value (); output(i) = (str1 == str2); } - else - output(i) = false; } } @@ -689,7 +671,7 @@ { // Broadcast the string. - boolNDArray output (cell.dimensions); + boolNDArray output (cell.dimensions, false); if (c < n) { @@ -704,15 +686,9 @@ { const std::string str2 = cell(i).string_value (); - if (str2.length() >= n) - { - if (str2.compare (0, n, str[0], 0, n) == 0) + if (str2.length() >= n + && str2.compare (0, n, str[0], 0, n) == 0) output(i) = true; - else - output(i) = false; - } - else - output(i) = false; } } } @@ -726,7 +702,7 @@ // Broadcast the cell. const dim_vector dv (r, 1); - boolNDArray output (dv); + boolNDArray output (dv, false); if (cell(0).is_string () && c >= n) { @@ -738,20 +714,8 @@ { if (str[i].compare (0, n, str2, 0, n) == 0) output(i) = true; - else - output(i) = false; } } - else - { - for (int i = 0; i < r; i++) - output(i) = false; - } - } - else - { - for (int i = 0; i < r; i++) - output(i) = false; } retval = output; @@ -760,14 +724,12 @@ { // Must match in all dimensions. - boolNDArray output (cell.dimensions); + boolNDArray output (cell.dimensions, false); if (cell.numel () == r) { for (int i = 0; i < r; i++) { - output(i) = false; - if (cell(i).is_string () && c >= n) { std::string str2 = cell(i).string_value (); @@ -815,18 +777,13 @@ const dim_vector size1 = cell1.dimensions; const dim_vector size2 = cell2.dimensions; - boolNDArray output (size1); + boolNDArray output (size1, false); if (r2 == 1) { // Broadcast cell2. - if (! cell2(0).is_string ()) - { - for (int i = 0; i < r1; i++) - output(i) = false; - } - else + if (cell2(0).is_string ()) { const std::string str2 = cell2(0).string_value (); @@ -839,11 +796,7 @@ if (str1.length () >= n && str2.length () >= n && str1.compare (0, n, str2, 0, n) == 0) output(i) = true; - else - output(i) = false; } - else - output(i) = false; } } } @@ -865,11 +818,7 @@ if (str1.length () >= n && str2.length () >= n && str1.compare (0, n, str2, 0, n) == 0) output(i) = true; - else - output(i) = false; } - else - output(i) = false; } } @@ -893,6 +842,7 @@ %!assert (all (strncmp ("abc", {"abcd", "bca", "abc"}, 4) == [0, 0, 0])) %!assert (all (strncmp ({"abcd", "bca", "abc"},"abce", 3) == [1, 0, 1])) %!assert (all (strncmp ({"abcd", "bca", "abc"},{"abcd", "bca", "abe"}, 3) == [1, 1, 0])) +%!assert (all (strncmp("abc", {"abcd", 10}, 2) == [1, 0])) */