24 #if defined (HAVE_CONFIG_H)
65 if (s[j] ==
'\\' && j+1 < len)
89 bool bad_esc_seq = (j+1 >= len);
92 if (! bad_esc_seq && s[++j] ==
'{')
100 for (k = j; k <
std::min (j+3+brace, len); k++)
102 int digit = s[
k] -
'0';
103 if (digit < 0 || digit > 7)
108 if (bad_esc_seq || (brace && s[k++] !=
'}'))
112 warning (
"malformed octal escape sequence '\\o' -- converting to '\\0'");
152 if (s[j] ==
'\\' && j+1 < len)
186 bool bad_esc_seq = (j+1 >= len);
189 if (! bad_esc_seq && s[++j] ==
'{')
197 for (k = j; k <
std::min (j+3+brace, len); k++)
199 int digit = s[
k] -
'0';
200 if (digit < 0 || digit > 7)
205 if (bad_esc_seq || (brace && s[k++] !=
'}'))
207 warning (
"malformed octal escape sequence '\\o' -- converting to '\\0'");
217 bool bad_esc_seq = (j+1 >= len);
220 if (! bad_esc_seq && s[++j] ==
'{')
228 for (k = j; k <
std::min (j+2+brace, len); k++)
230 if (! isxdigit (s[k]))
236 tmpi += digit -
'a' + 10;
237 else if (digit >=
'A')
238 tmpi += digit -
'A' + 10;
242 if (bad_esc_seq || (brace && s[k++] !=
'}'))
244 warning (
"malformed hex escape sequence '\\x' -- converting to '\\0'");
257 retval[
i] =
'\\'; retval[++
i] =
'$';
261 retval[
i] =
'\\'; retval[++
i] =
'\\';
285 const std::string& who,
int skip,
bool& extra_args)
289 for (
int i = skip;
i < args.
length ();
i++)
293 str =
args(
i).xstring_value (
"%s: optional arguments must be strings", who.c_str ());
297 if (str.find (
"once", 0) == 0)
299 else if (str.find (
"matchcase", 0) == 0)
301 else if (str.find (
"ignorecase", 0) == 0)
303 else if (str.find (
"dotall", 0) == 0)
305 else if (str.find (
"stringanchors", 0) == 0)
307 else if (str.find (
"literalspacing", 0) == 0)
309 else if (str.find (
"noemptymatch", 0) == 0)
311 else if (str.find (
"dotexceptnewline", 0) == 0)
313 else if (str.find (
"lineanchors", 0) == 0)
315 else if (str.find (
"freespacing", 0) == 0)
317 else if (str.find (
"emptymatch", 0) == 0)
319 else if (str.find (
"start", 0) == 0
320 || str.find (
"end", 0) == 0
321 || str.find (
"tokenextents", 0) == 0
322 || str.find (
"match", 0) == 0
323 || str.find (
"tokens", 0) == 0
324 || str.find (
"names", 0) == 0
325 || str.find (
"split", 0) == 0)
328 error (
"%s: unrecognized option", who.c_str ());
334 const std::string &who,
bool case_insensitive =
false)
350 bool extra_options =
false;
358 size_t sz = rx_lst.
size ();
371 for (
int j = 0; j < named_pats.
numel (); j++)
372 nmap.
assign (named_pats(j), named_tokens(j));
378 for (
int j = 0; j < named_pats.
numel (); j++)
384 p != rx_lst.
end ();
p++)
388 tmp(i++) = named_tokens(j);
402 retval(3) = sz ? p->match_string () :
"";
407 double start = p->start ();
408 double end = p->end ();
411 split(0) = buffer.substr (0, start-1);
412 split(1) = buffer.substr (end);
437 p != rx_lst.
end ();
p++)
439 double s =
p->start ();
440 double e =
p->end ();
444 match_string(i) =
p->match_string ();
445 token_extents(i) =
p->token_extents ();
448 split(i) = buffer.substr (sp_start, s-sp_start-1);
453 split(i) = buffer.substr (sp_start);
458 retval(2) = token_extents;
469 new_retval.
resize (nargout);
472 for (
int j = 0; j < 6; j++)
475 for (
int j = 2; j <
nargin; j++)
481 if (str.find (
"once", 0) == 0
482 || str.find (
"stringanchors", 0) == 0
483 || str.find (
"lineanchors", 0) == 0
484 || str.find (
"matchcase", 0) == 0
485 || str.find (
"ignorecase", 0) == 0
486 || str.find (
"dotall", 0) == 0
487 || str.find (
"dotexceptnewline", 0) == 0
488 || str.find (
"literalspacing", 0) == 0
489 || str.find (
"freespacing", 0) == 0
490 || str.find (
"noemptymatch", 0) == 0
491 || str.find (
"emptymatch", 0) == 0)
493 else if (str.find (
"start", 0) == 0)
495 else if (str.find (
"end", 0) == 0)
497 else if (str.find (
"tokenextents", 0) == 0)
499 else if (str.find (
"match", 0) == 0)
501 else if (str.find (
"tokens", 0) == 0)
503 else if (str.find (
"names", 0) == 0)
505 else if (str.find (
"split", 0) == 0)
508 new_retval(n++) =
retval(k);
518 for (
int j = 0; j < 6; j++)
521 new_retval(n++) =
retval(j);
533 const std::string &who,
bool case_insensitive =
false)
537 if (
args(0).is_cell ())
541 Cell cellstr =
args(0).cell_value ();
542 if (
args(1).is_cell ())
544 Cell cellpat =
args(1).cell_value ();
546 if (cellpat.
numel () == 1)
548 for (
int j = 0; j <
nargout; j++)
549 newretval[j].resize (cellstr.
dims ());
551 new_args(1) = cellpat(0);
555 new_args(0) = cellstr(
i);
559 for (
int j = 0; j <
nargout; j++)
560 newretval[j](
i) =
tmp(j);
563 else if (cellstr.
numel () == 1)
565 for (
int j = 0; j <
nargout; j++)
566 newretval[j].resize (cellpat.
dims ());
568 new_args(0) = cellstr(0);
572 new_args(1) = cellpat(
i);
576 for (
int j = 0; j <
nargout; j++)
577 newretval[j](
i) =
tmp(j);
580 else if (cellstr.
numel () == cellpat.
numel ())
582 if (cellstr.
dims () != cellpat.
dims ())
583 error (
"%s: inconsistent cell array dimensions", who.c_str ());
585 for (
int j = 0; j <
nargout; j++)
586 newretval[j].resize (cellstr.
dims ());
590 new_args(0) = cellstr(
i);
591 new_args(1) = cellpat(
i);
596 for (
int j = 0; j <
nargout; j++)
597 newretval[j](
i) =
tmp(j);
601 error (
"regexp: cell array arguments must be scalar or equal size");
605 for (
int j = 0; j <
nargout; j++)
606 newretval[j].resize (cellstr.
dims ());
610 new_args(0) = cellstr(
i);
614 for (
int j = 0; j <
nargout; j++)
615 newretval[j](
i) =
tmp(j);
619 for (
int j = 0; j <
nargout; j++)
622 else if (
args(1).is_cell ())
626 Cell cellpat =
args(1).cell_value ();
628 for (
int j = 0; j <
nargout; j++)
629 newretval[j].resize (cellpat.
dims ());
633 new_args(1) = cellpat(
i);
637 for (
int j = 0; j <
nargout; j++)
638 newretval[j](
i) =
tmp(j);
641 for (
int j = 0; j <
nargout; j++)
645 retval =
octregexp (args, nargout, who, case_insensitive);
858 if (
args.length () < 2)
863 if (
args(0).is_cell () ||
args(1).is_cell ())
1153 if (
args.length () < 2)
1156 if (
args(0).is_cell () ||
args(1).is_cell ())
1312 if (
args(2).is_sq_string ())
1323 if (opt !=
"tokenize" && opt !=
"start" && opt !=
"end"
1324 && opt !=
"tokenextents" && opt !=
"match" && opt !=
"tokens"
1325 && opt !=
"names" && opt !=
"split" && opt !=
"warnings")
1327 regexpargs(len++) =
args(
i);
1330 regexpargs.resize (len);
1333 bool extra_args =
false;
1339 DEFUN (regexprep, args, ,
1384 if (
args(0).is_cell () ||
args(1).is_cell () ||
args(2).is_cell ())
1390 if (
args(0).is_cell ())
1391 str =
args(0).cell_value ();
1395 if (
args(1).is_cell ())
1396 pat =
args(1).cell_value ();
1400 if (
args(2).is_cell ())
1401 rep =
args(2).cell_value ();
1406 if (pat.
numel () != 1)
1409 if (rep.
numel () != 1 && dv1 != rep.
dims ())
1410 error (
"regexprep: inconsistent cell array dimensions");
1412 else if (rep.
numel () != 1)
1420 new_args(0) =
str(
i);
1421 if (pat.
numel () == 1)
1422 new_args(1) = pat(0);
1423 if (rep.
numel () == 1)
1424 new_args(2) = rep(0);
1428 if (pat.
numel () != 1)
1429 new_args(1) = pat(j);
1430 if (rep.
numel () != 1)
1431 new_args(2) = rep(j);
1432 new_args(0) = octregexprep (new_args,
"regexprep");
1435 ret(
i) = new_args(0);
1438 retval =
args(0).is_cell () ?
ovl (ret)
1442 retval = octregexprep (args,
"regexprep");
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
#define DEFUN(name, args_name, nargout_name, doc)
void error(const char *fmt,...)
static octave_value_list octcellregexp(const octave_value_list &args, int nargout, const std::string &who, bool case_insensitive=false)
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
static std::string do_regexp_rep_string_escapes(const std::string &s)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
static std::string do_regexp_ptn_string_escapes(const std::string &s, bool is_sq_str)
void dotexceptnewline(bool val)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
static octave_value_list octregexp(const octave_value_list &args, int nargout, const std::string &who, bool case_insensitive=false)
static void parse_options(octave::regexp::opts &options, const octave_value_list &args, const std::string &who, int skip, bool &extra_args)
std::string replace(const std::string &buffer, const std::string &replacement)
octave_idx_type length(void) const
void warning(const char *fmt,...)
match_data match(const std::string &buffer)
std::list< match_element >::const_iterator const_iterator
void emptymatch(bool val)
=val(i)}if ode{val(i)}occurs in table i
is longer than or if then or only for unique occurrences of the complete pattern(false).The default is true.If a cell array of strings ar
void assign(const std::string &k, const octave_value &val)
string_vector named_patterns(void)
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
ColumnVector transform(const Matrix &m, double x, double y, double z)
void case_insensitive(bool val)
void lineanchors(bool val)
Vector representing the dimensions (size) of an Array.
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
charNDArray min(char d, const charNDArray &m)
void freespacing(bool val)