# HG changeset patch # User jwe # Date 832910932 0 # Node ID 38fea6d34dafcea524197ac5177d8e50a62b5bd4 # Parent 9750746d7da5e1859a2a9798cb4a85282a011600 [project @ 1996-05-24 04:06:52 by jwe] diff -r 9750746d7da5 -r 38fea6d34daf scripts/strings/findstr.m --- a/scripts/strings/findstr.m Fri May 24 04:06:42 1996 +0000 +++ b/scripts/strings/findstr.m Fri May 24 04:08:52 1996 +0000 @@ -16,17 +16,29 @@ # along with Octave; see the file COPYING. If not, write to the Free # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -function v = findstr (s, t) +function v = findstr (s, t, overlap) -# usage: findstr (s, t) +# usage: findstr (s, t [, overlap]) # # Returns the vector of all positions in the longer of the two strings # S and T where an occurence of the shorter of the two starts. - +# +# If the optional argument OVERLAP is nonzero, the returned vector +# can include overlapping positions (this is the default). +# +# For example, +# +# findstr ("abababa", "aba") => [1, 3, 5] +# findstr ("abababa", "aba", 0) => [1, 5] + # Original version by Kurt Hornik . - if (nargin != 2) - usage ("findstr (s, t)"); + if (nargin < 2 || nargin > 3) + usage ("findstr (s, t [, overlap])"); + endif + + if (nargin == 2) + overlap = 1; endif if (isstr (s) && isstr (t)) @@ -42,16 +54,23 @@ s = toascii (s); t = toascii (t); - ind = 1 : length (t); - limit = length (s) - length (t) + 1; + l_t = length (t); + + ind = 1 : l_t; + limit = length (s) - l_t + 1; v = zeros (1, limit); i = 0; - for k = 1 : limit + k = 1; + while (k <= limit) if (s (ind + k - 1) == t) v (++i) = k; + if (! overlap) + k = k + l_t - 1; + endif endif - endfor + k++; + endwhile if (i > 0) v = v (1:i); @@ -60,7 +79,7 @@ endif else - error ("findstr: both arguments must be strings"); + error ("findstr: expecting first two arguments to be strings"); endif endfunction diff -r 9750746d7da5 -r 38fea6d34daf src/input.cc --- a/src/input.cc Fri May 24 04:06:42 1996 +0000 +++ b/src/input.cc Fri May 24 04:08:52 1996 +0000 @@ -401,11 +401,11 @@ } char * -gnu_readline (const char *s) +gnu_readline (const char *s, bool force_readline) { char *retval = 0; - if (using_readline) + if (using_readline || force_readline) { char *tmp = retval = ::readline (s); @@ -1010,7 +1010,7 @@ flush_octave_stdout (); - char *input_buf = gnu_readline (prompt.c_str ()); + char *input_buf = gnu_readline (prompt.c_str (), true); if (input_buf) { diff -r 9750746d7da5 -r 38fea6d34daf src/input.h --- a/src/input.h Fri May 24 04:06:42 1996 +0000 +++ b/src/input.h Fri May 24 04:08:52 1996 +0000 @@ -67,7 +67,7 @@ // A line of input. extern string current_input_line; -char *gnu_readline (const char *s); +char *gnu_readline (const char *s, bool force_readline = false); extern string Vps4; diff -r 9750746d7da5 -r 38fea6d34daf src/mappers.h --- a/src/mappers.h Fri May 24 04:06:42 1996 +0000 +++ b/src/mappers.h Fri May 24 04:08:52 1996 +0000 @@ -47,19 +47,18 @@ { builtin_mapper_function (ch_Mapper ch = 0, d_d_Mapper dd = 0, d_c_Mapper dc = 0, c_c_Mapper cc = 0, - double l = 0.0, double u = 0.0, int cfr = 0, + double l = 0.0, double u = 0.0, int f = 0, const string n = string (), const string& h = string ()) : ch_mapper (ch), d_d_mapper (dd), d_c_mapper (dc), c_c_mapper (cc), - lower_limit (l), upper_limit (u), can_return_complex_for_real_arg (cfr), + lower_limit (l), upper_limit (u), flag (f), name (n), help_string (h) { } builtin_mapper_function (const builtin_mapper_function& mf) : ch_mapper (mf.ch_mapper), d_d_mapper (mf.d_d_mapper), d_c_mapper (mf.d_c_mapper), c_c_mapper (mf.c_c_mapper), lower_limit (mf.lower_limit), upper_limit (mf.upper_limit), - can_return_complex_for_real_arg (mf.can_return_complex_for_real_arg), - name (mf.name), help_string (mf.help_string) { } + flag (mf.flag), name (mf.name), help_string (mf.help_string) { } builtin_mapper_function& operator = (const builtin_mapper_function& mf) { @@ -71,7 +70,7 @@ c_c_mapper = mf.c_c_mapper; lower_limit = mf.lower_limit; upper_limit = mf.upper_limit; - can_return_complex_for_real_arg = mf.can_return_complex_for_real_arg; + flag = mf.flag; name = mf.name; help_string = mf.help_string; } @@ -86,7 +85,17 @@ c_c_Mapper c_c_mapper; double lower_limit; double upper_limit; - int can_return_complex_for_real_arg; + + // For ch_mapper: + // + // 0 => this function returns a matrix of ones and zeros + // 1 => this function returns a numeric matrix (any values) + // 2 => this function returns a string array + // + // For other mappers, nonzero means that this function can return a + // complex value for some real arguments. + int flag; + string name; string help_string; }; diff -r 9750746d7da5 -r 38fea6d34daf src/pt-const.cc --- a/src/pt-const.cc Fri May 24 04:06:42 1996 +0000 +++ b/src/pt-const.cc Fri May 24 04:08:52 1996 +0000 @@ -2949,7 +2949,16 @@ break; case char_matrix_constant_str: - retval = octave_value (charMatrix (char_matrix->value ()), 1); + { + // Kluge to prevent s([]) from turning into a string + // with no rows... + charMatrix tmp (char_matrix->value ()); + + if (tmp.rows () == 0 && tmp.columns () == 0) + tmp.resize (1, 0); + + retval = octave_value (tmp, 1); + } break; default: