26 #if defined (HAVE_CONFIG_H)
50 #define ORD(ch) static_cast<unsigned char> (ch)
51 #define TABSIZE (std::numeric_limits<unsigned char>::max () + 1)
59 const char *
x = needle.
data ();
65 table[
ORD(
x[i])] =
m - i;
74 const char *
x = needle.
data ();
76 const char *y = haystack.
data ();
81 std::deque<octave_idx_type> accum;
98 if (y[i] ==
x[0] && y[i+1] ==
x[1])
106 if (y[i] ==
x[0] && y[i+1] ==
x[1])
107 accum.push_back (i++);
120 if (std::equal (
x,
x +
m, y + j))
122 j += table[
ORD(y[j +
m])];
129 if (std::equal (
x,
x +
m, y + j))
135 j += table[
ORD(y[j +
m])];
139 if (j ==
n -
m && std::equal (
x,
x +
m, y + j))
147 for (
const auto& idx : accum)
148 result.xelem (k++) = idx;
153 DEFUN (strfind, args, ,
215 int nargin = args.length ();
217 if (nargin != 4 && nargin != 2)
220 bool overlaps =
true;
221 bool forcecelloutput =
false;
224 if (! args(2).is_string () || ! args(3).is_scalar_type ())
225 error (
"strfind: invalid optional arguments");
227 std::string opt = args(2).string_value ();
230 if (opt ==
"overlaps")
231 overlaps = args(3).bool_value ();
232 else if (opt ==
"forcecelloutput")
233 forcecelloutput = args(3).bool_value ();
235 error (
"strfind: unknown option: %s", opt.c_str ());
247 qs_preprocess (needle, table);
260 retval =
Cell (retval);
262 else if (argstr.
iscell ())
272 error (
"strfind: each element of CELLSTR must be a string");
286 error (
"strfind: first argument must be a string or cell array of strings");
288 else if (argpat.
iscell ())
291 error (
"strfind: PATTERN must be a string or cell array of strings");
323 bool overlaps =
true)
359 retsiz = siz + nidx * (rsiz - psiz);
366 const char *src = str.
data ();
367 const char *reps = rep.
data ();
375 dest = std::copy (src + k, src + j, dest);
376 dest = std::copy (reps, reps + rsiz, dest);
380 std::copy (src + k, src + siz, dest);
388 DEFUN (strrep, args, ,
415 int nargin = args.length ();
417 if (nargin != 3 && nargin != 5)
420 bool overlaps =
true;
424 if (! args(3).is_string () || ! args(4).is_scalar_type ())
425 error (
"strrep: invalid optional argument");
427 std::string opt = args(3).string_value ();
428 if (opt !=
"overlaps")
429 error (
"strrep: unknown option: %s", opt.c_str ());
431 overlaps = args(4).bool_value ();
447 qs_preprocess (pat, table);
450 if (argstr.
rows () == 1)
463 rowchm = qs_replace (argchm.
extract (i, 0, i, nc-1),
464 pat, rep, table, overlaps);
465 retchm.
insert (rowchm, i, 0);
470 else if (argstr.
iscell ())
474 error (
"strrep: each element of S must be a string");
481 retcell(i) = qs_replace (argcell(i).char_array_value (),
482 pat, rep, table, overlaps);
488 error (
"strrep: S must be a string or cell array of strings");
493 error (
"strrep: PTN and REP arguments must be strings or cell arrays of strings");
524 OCTAVE_END_NAMESPACE(
octave)
charNDArray min(char d, const charNDArray &m)
T * fortran_vec()
Size of the specified dimension.
octave_idx_type rows() const
const T * data() const
Size of the specified dimension.
octave_idx_type columns() const
const dim_vector & dims() const
Return a const-reference so that dims ()(i) works efficiently.
octave_idx_type numel() const
Number of elements in the array.
charMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
charMatrix & insert(const char *s, octave_idx_type r, octave_idx_type c)
Vector representing the dimensions (size) of an Array.
charMatrix char_matrix_value(bool frc_str_conv=false) const
octave_idx_type rows() const
charNDArray char_array_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void() error(const char *fmt,...)
ColumnVector transform(const Matrix &m, double x, double y, double z)
F77_RET_T const F77_DBLE * x
octave_value_list do_simple_cellfun(octave_value_list(*fcn)(const octave_value_list &, int), const char *fcn_name, const octave_value_list &args, int nargout)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list Fstrfind(const octave_value_list &args, int)
octave_value_list Fstrrep(const octave_value_list &args, int)