changeset 24473:42d099b841aa

erase.m: Add warning if a character array is used for PTN. * erase.m: Add warning when PTN is a char array. Also add BIST test for new behavior. * warning_ids.m: Document new warning ID "Octave:erase:chararray".
author Rik <rik@octave.org>
date Wed, 27 Dec 2017 08:59:41 -0800
parents 19d63669d174
children 0b65949870e3
files scripts/help/warning_ids.m scripts/strings/erase.m
diffstat 2 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/help/warning_ids.m	Tue Dec 26 15:23:43 2017 -0800
+++ b/scripts/help/warning_ids.m	Wed Dec 27 08:59:41 2017 -0800
@@ -170,6 +170,13 @@
 ## By default, the @code{Octave:eigs:UnconvergedEigenvalues} warning is
 ## enabled.
 ##
+## @item Octave:erase:chararray
+## If the @code{Octave:erase:chararray} warning is enabled then the erase
+## function will issue a warning if the input pattern is a character array
+## rather than a string or cell array of strings.
+## By default, the @code{Octave:eigs:UnconvergedEigenvalues} warning is
+## enabled.
+##
 ## @item Octave:fopen-file-in-path
 ## By default, the @code{Octave:fopen-file-in-path} warning is enabled.
 ##
--- a/scripts/strings/erase.m	Tue Dec 26 15:23:43 2017 -0800
+++ b/scripts/strings/erase.m	Wed Dec 27 08:59:41 2017 -0800
@@ -80,6 +80,8 @@
 
   if (ischar (ptn)) 
     if (rows (ptn) > 1)
+      warning ("Octave:erase:chararray",
+               "erase: using character array for PTN is not recommended, consider cell array of strings instead");
       ## Convert to cell.  Can't use cellstr which trims spaces.
       ptn = mat2cell (ptn, ones (1, rows (ptn)));
     endif
@@ -137,3 +139,5 @@
 %!error erase ("a", "b", "c")
 %!error <STR must be a string> erase ([1], "foo") 
 %!error <PTN must be a string> erase ("foo", [1]) 
+%!warning <using character array for PTN is not recommended>
+%! erase ("a", ["a";"b"]);