26 #if defined (HAVE_CONFIG_H)
38 #include "builtin-defun-decls.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 ());
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 ();
450 if (argstr.
rows () == 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");
charNDArray min(char d, const charNDArray &m)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type columns(void) const
OCTARRAY_API void clear(void)
OCTARRAY_OVERRIDABLE_FUNC_API const T * data(void) const
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
bool iscellstr(void) const
OCTAVE_API charMatrix extract(octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
OCTAVE_API 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(void) const
bool is_string(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
Cell cell_value(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
OCTINTERP_API void print_usage(void)
#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
#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_EXPORT octave_value_list Fstrfind(const octave_value_list &args, int)
OCTAVE_EXPORT octave_value_list Fstrrep(const octave_value_list &args, int)
static Array< octave_idx_type > qs_search(const Array< char > &needle, const Array< char > &haystack, const octave_idx_type *table, bool overlaps=true)
static Array< char > qs_replace(const Array< char > &str, const Array< char > &pat, const Array< char > &rep, const octave_idx_type *table, bool overlaps=true)
static void qs_preprocess(const Array< char > &needle, octave_idx_type *table)
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)