26 #if defined (HAVE_CONFIG_H)
38 #include "builtin-defun-decls.h"
48 #define ORD(ch) static_cast<unsigned char>(ch)
49 #define TABSIZE (std::numeric_limits<unsigned char>::max () + 1)
57 const char *
x = needle.
data ();
63 table[
ORD(
x[i])] =
m - i;
72 const char *
x = needle.
data ();
74 const char *y = haystack.
data ();
79 std::deque<octave_idx_type> accum;
96 if (y[i] ==
x[0] && y[i+1] ==
x[1])
104 if (y[i] ==
x[0] && y[i+1] ==
x[1])
105 accum.push_back (i++);
118 if (std::equal (
x,
x +
m, y + j))
120 j += table[
ORD(y[j +
m])];
127 if (std::equal (
x,
x +
m, y + j))
133 j += table[
ORD(y[j +
m])];
137 if (j ==
n -
m && std::equal (
x,
x +
m, y + j))
145 for (
const auto& idx : accum)
146 result.
xelem (k++) = idx;
151 DEFUN (strfind, args, ,
213 int nargin = args.length ();
215 if (nargin != 4 && nargin != 2)
218 bool overlaps =
true;
219 bool forcecelloutput =
false;
222 if (! args(2).is_string () || ! args(3).is_scalar_type ())
223 error (
"strfind: invalid optional arguments");
225 std::string opt = args(2).string_value ();
228 if (opt ==
"overlaps")
229 overlaps = args(3).bool_value ();
230 else if (opt ==
"forcecelloutput")
231 forcecelloutput = args(3).bool_value ();
233 error (
"strfind: unknown option: %s", opt.c_str ());
260 else if (argstr.
iscell ())
270 error (
"strfind: each element of CELLSTR must be a string");
284 error (
"strfind: first argument must be a string or cell array of strings");
286 else if (argpat.
iscell ())
289 error (
"strfind: PATTERN must be a string or cell array of strings");
319 bool overlaps =
true)
355 retsiz = siz + nidx * (rsiz - psiz);
362 const char *src = str.
data ();
363 const char *reps = rep.
data ();
371 dest = std::copy (src + k, src + j, dest);
372 dest = std::copy (reps, reps + rsiz, dest);
376 std::copy (src + k, src + siz, dest);
384 DEFUN (strrep, args, ,
411 int nargin = args.length ();
413 if (nargin != 3 && nargin != 5)
416 bool overlaps =
true;
420 if (! args(3).is_string () || ! args(4).is_scalar_type ())
421 error (
"strrep: invalid optional arguments");
423 std::string opt = args(3).string_value ();
424 if (opt ==
"overlaps")
425 overlaps = args(4).bool_value ();
427 error (
"strrep: unknown option: %s", opt.c_str ());
447 else if (argstr.
iscell ())
460 error (
"strrep: each element of S must be a string");
466 error (
"strrep: S must be a string or cell array of strings");
471 error (
"strrep: PTN and REP arguments must be strings or cell arrays of strings");
charNDArray min(char d, const charNDArray &m)
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
const T * data(void) const
Size of the specified dimension.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
const T * fortran_vec(void) const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
bool is_string(void) const
charNDArray char_array_value(bool frc_str_conv=false) const
Cell cell_value(void) const
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
octave_value_list do_simple_cellfun(octave_value_list(*fun)(const octave_value_list &, int), const char *fun_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::octave_value(const Array< char > &chm, char type) return retval
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)