24 #if defined (HAVE_CONFIG_H) 59 size_t len =
s.length ();
65 if (
s[j] ==
'\\' && j+1 < len)
89 bool bad_esc_seq = (j+1 >= len);
92 if (! bad_esc_seq &&
s[++j] ==
'{')
102 int digit =
s[
k] -
'0';
103 if (digit < 0 || digit > 7)
108 if (bad_esc_seq || (brace &&
s[
k++] !=
'}'))
112 warning (R
"(malformed octal escape sequence '\o' -- converting to '\0')"); 146 size_t len =
s.length ();
152 if (
s[j] ==
'\\' && j+1 < len)
194 int tmpi =
s[j] -
'0';
197 int digit =
s[
k] -
'0';
198 if (digit < 0 || digit > 7)
210 bool bad_esc_seq = (j+1 >= len);
213 if (! bad_esc_seq &&
s[++j] ==
'{')
223 int digit =
s[
k] -
'0';
224 if (digit < 0 || digit > 7)
229 if (bad_esc_seq || (brace &&
s[
k++] !=
'}'))
231 warning (R
"(malformed octal escape sequence '\o' -- converting to '\0')"); 241 bool bad_esc_seq = (j+1 >= len);
244 if (! bad_esc_seq &&
s[++j] ==
'{')
254 if (! isxdigit (
s[
k]))
260 tmpi += digit -
'a' + 10;
261 else if (digit >=
'A')
262 tmpi += digit -
'A' + 10;
266 if (bad_esc_seq || (brace &&
s[
k++] !=
'}'))
268 warning (R
"(malformed hex escape sequence '\x' -- converting to '\0')"); 309 const std::string& who,
int skip,
bool& extra_args)
313 for (
int i = skip;
i < args.
length ();
i++)
317 str = args(
i).xstring_value (
"%s: optional arguments must be strings", who.c_str ());
321 if (
str.find (
"once", 0) == 0)
323 else if (
str.find (
"matchcase", 0) == 0)
324 options.case_insensitive (
false);
325 else if (
str.find (
"ignorecase", 0) == 0)
326 options.case_insensitive (
true);
327 else if (
str.find (
"dotall", 0) == 0)
328 options.dotexceptnewline (
false);
329 else if (
str.find (
"stringanchors", 0) == 0)
331 else if (
str.find (
"literalspacing", 0) == 0)
333 else if (
str.find (
"noemptymatch", 0) == 0)
335 else if (
str.find (
"dotexceptnewline", 0) == 0)
336 options.dotexceptnewline (
true);
337 else if (
str.find (
"lineanchors", 0) == 0)
339 else if (
str.find (
"freespacing", 0) == 0)
341 else if (
str.find (
"emptymatch", 0) == 0)
343 else if (
str.find (
"start", 0) == 0
344 ||
str.find (
"end", 0) == 0
345 ||
str.find (
"tokenextents", 0) == 0
346 ||
str.find (
"match", 0) == 0
347 ||
str.find (
"tokens", 0) == 0
348 ||
str.find (
"names", 0) == 0
349 ||
str.find (
"split", 0) == 0)
352 error (
"%s: unrecognized option", who.c_str ());
358 const std::string& who,
bool case_insensitive =
false)
365 const std::string buffer = args(0).string_value ();
373 options.case_insensitive (case_insensitive);
374 bool extra_options =
false;
382 size_t sz = rx_lst.
size ();
392 for (
int j = 0; j < named_pats.
numel (); j++)
397 for (
const auto& match_data : rx_lst)
401 ctmp(
i++) = named_tokens(j);
404 nmap.
assign (named_pats(j), ctmp);
414 retval(3) = (
sz ?
p->match_string () :
"");
419 double start =
p->start ();
420 double end =
p->end ();
423 split(0) = buffer.substr (0,
start-1);
424 split(1) = buffer.substr (end);
448 for (
const auto& match_data : rx_lst)
450 double s = match_data.start ();
451 double e = match_data.end ();
455 match_string(
i) = match_data.match_string ();
456 token_extents(
i) = match_data.token_extents ();
459 split(
i) = buffer.substr (sp_start,
s-sp_start-1);
464 split(
i) = buffer.substr (sp_start);
469 retval(2) = token_extents;
484 for (
int j = 2; j <
nargin; j++)
490 if (
str.find (
"once", 0) == 0
491 ||
str.find (
"stringanchors", 0) == 0
492 ||
str.find (
"lineanchors", 0) == 0
493 ||
str.find (
"matchcase", 0) == 0
494 ||
str.find (
"ignorecase", 0) == 0
495 ||
str.find (
"dotall", 0) == 0
496 ||
str.find (
"dotexceptnewline", 0) == 0
497 ||
str.find (
"literalspacing", 0) == 0
498 ||
str.find (
"freespacing", 0) == 0
499 ||
str.find (
"noemptymatch", 0) == 0
500 ||
str.find (
"emptymatch", 0) == 0)
502 else if (
str.find (
"start", 0) == 0)
504 else if (
str.find (
"end", 0) == 0)
506 else if (
str.find (
"tokenextents", 0) == 0)
508 else if (
str.find (
"match", 0) == 0)
510 else if (
str.find (
"tokens", 0) == 0)
512 else if (
str.find (
"names", 0) == 0)
514 else if (
str.find (
"split", 0) == 0)
527 for (
int j = 0; j < 7; j++)
530 new_retval(n++) =
retval(j);
542 const std::string& who,
bool case_insensitive =
false)
546 if (args(0).iscell ())
551 if (args(1).iscell ())
555 if (cellpat.
numel () == 1)
557 for (
int j = 0; j <
nargout; j++)
560 new_args(1) = cellpat(0);
564 new_args(0) = cellstr(
i);
568 for (
int j = 0; j <
nargout; j++)
569 newretval[j](
i) =
tmp(j);
572 else if (cellstr.
numel () == 1)
574 for (
int j = 0; j <
nargout; j++)
577 new_args(0) = cellstr(0);
581 new_args(1) = cellpat(
i);
585 for (
int j = 0; j <
nargout; j++)
586 newretval[j](
i) =
tmp(j);
589 else if (cellstr.
numel () == cellpat.
numel ())
591 if (cellstr.
dims () != cellpat.
dims ())
592 error (
"%s: inconsistent cell array dimensions", who.c_str ());
594 for (
int j = 0; j <
nargout; j++)
599 new_args(0) = cellstr(
i);
600 new_args(1) = cellpat(
i);
605 for (
int j = 0; j <
nargout; j++)
606 newretval[j](
i) =
tmp(j);
610 error (
"regexp: cell array arguments must be scalar or equal size");
614 for (
int j = 0; j <
nargout; j++)
619 new_args(0) = cellstr(
i);
623 for (
int j = 0; j <
nargout; j++)
624 newretval[j](
i) =
tmp(j);
628 for (
int j = 0; j <
nargout; j++)
631 else if (args(1).iscell ())
637 for (
int j = 0; j <
nargout; j++)
642 new_args(1) = cellpat(
i);
646 for (
int j = 0; j <
nargout; j++)
647 newretval[j](
i) =
tmp(j);
650 for (
int j = 0; j <
nargout; j++)
881 if (args.length () < 2)
886 if (args(0).iscell () || args(1).iscell ())
1205 if (args.length () < 2)
1208 if (args(0).iscell () || args(1).iscell ())
1354 const std::string buffer = args(0).string_value ();
1361 std::string replacement = args(2).string_value ();
1364 if (args(2).is_sq_string ())
1375 if (opt !=
"tokenize" && opt !=
"start" && opt !=
"end" 1376 && opt !=
"tokenextents" && opt !=
"match" && opt !=
"tokens" 1377 && opt !=
"names" && opt !=
"split" && opt !=
"warnings")
1379 regexpargs(len++) = args(
i);
1382 regexpargs.resize (len);
1385 bool extra_args =
false;
1391 DEFUN (regexprep, args, ,
1436 if (args(0).iscell () || args(1).iscell () || args(2).iscell ())
1442 if (args(0).iscell ())
1447 if (args(1).iscell ())
1450 pat =
Cell (args(1));
1452 if (args(2).iscell ())
1458 if (pat.
numel () != 1)
1462 error (
"regexprep: inconsistent cell array dimensions");
1472 new_args(0) =
str(
i);
1473 if (pat.
numel () == 1)
1474 new_args(1) = pat(0);
1476 new_args(2) =
rep(0);
1480 if (pat.
numel () != 1)
1481 new_args(1) = pat(j);
1483 new_args(2) =
rep(j);
1484 new_args(0) = octregexprep (new_args,
"regexprep");
1487 ret(
i) = new_args(0);
1490 retval = (args(0).iscell () ?
ovl (ret) :
ovl (ret(0)));
1493 retval = octregexprep (args,
"regexprep");
void assign(const std::string &k, const Cell &val)
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,...)
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
static octave_value_list octcellregexp(const octave_value_list &args, int nargout, const std::string &who, bool case_insensitive=false)
octave_idx_type numel(void) const
static std::string do_regexp_rep_string_escapes(const std::string &s)
octave_value resize(const dim_vector &dv, bool fill=false) const
static std::string do_regexp_ptn_string_escapes(const std::string &s, bool is_sq_str)
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)
void resize(const dim_vector &dv, const T &rfv)
Resizing (with fill).
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)
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 warning(const char *fmt,...)
match_data match(const std::string &buffer)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
std::list< match_element >::const_iterator const_iterator
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).isinteger())
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
string_vector named_patterns(void)
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
Cell cell_value(void) const
octave_idx_type length(void) const
#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)
octave_idx_type numel(void) const
Number of elements in the array.
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
charNDArray min(char d, const charNDArray &m)
Array< T >::ArrayRep * rep