Skip to content

Commit eb1cf88

Browse files
author
ripley
committed
finish using asRbool for grep & co
git-svn-id: https://svn.r-project.org/R/trunk@87812 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 9355565 commit eb1cf88

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -634,10 +634,9 @@
634634
\code{unlink(, recursive)}, \code{tempdir()} and the \code{na.rm}
635635
argument of \code{max()}, \code{min()}, \code{sum()}, \dots.
636636

637-
\code{grep()} and similar took non-\code{TRUE} values of their logical
638-
arguments as \code{FALSE}, but these were almost always coding
639-
mistakes and are now reported as \code{NA}. [In progress, in place
640-
for \code{regexpr()}.]
637+
\code{grep()}, \code{strsplit()} and similar took non-\code{TRUE}
638+
values of their logical arguments as \code{FALSE}, but these were
639+
almost always mistakes and are now reported as \code{NA}.
641640
}
642641
}
643642
}

src/main/grep.c

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ attribute_hidden SEXP do_grep(SEXP call, SEXP op, SEXP args, SEXP env)
12541254
regex_t reg;
12551255
R_xlen_t i, j, n;
12561256
int nmatches = 0, rc;
1257-
int igcase_opt, value_opt, perl_opt, fixed_opt, useBytes, invert;
1257+
Rboolean igcase_opt, value_opt, perl_opt, fixed_opt, useBytes, invert;
12581258
const char *spat = NULL;
12591259
const wchar_t *wpat = NULL;
12601260
const unsigned char *tables = NULL /* -Wall */;
@@ -1276,18 +1276,12 @@ attribute_hidden SEXP do_grep(SEXP call, SEXP op, SEXP args, SEXP env)
12761276
checkArity(op, args);
12771277
pat = CAR(args); args = CDR(args);
12781278
text = CAR(args); args = CDR(args);
1279-
igcase_opt = asLogical(CAR(args)); args = CDR(args);
1280-
value_opt = asLogical(CAR(args)); args = CDR(args);
1281-
perl_opt = asLogical(CAR(args)); args = CDR(args);
1282-
fixed_opt = asLogical(CAR(args)); args = CDR(args);
1283-
useBytes = asLogical(CAR(args)); args = CDR(args);
1284-
invert = asLogical(CAR(args));
1285-
if (igcase_opt == NA_INTEGER) igcase_opt = 0;
1286-
if (value_opt == NA_INTEGER) value_opt = 0;
1287-
if (perl_opt == NA_INTEGER) perl_opt = 0;
1288-
if (fixed_opt == NA_INTEGER) fixed_opt = 0;
1289-
if (useBytes == NA_INTEGER) useBytes = 0;
1290-
if (invert == NA_INTEGER) invert = 0;
1279+
igcase_opt = asRbool(CAR(args), call); args = CDR(args);
1280+
value_opt = asRbool(CAR(args), call); args = CDR(args);
1281+
perl_opt = asRbool(CAR(args), call); args = CDR(args);
1282+
fixed_opt = asRbool(CAR(args), call); args = CDR(args);
1283+
useBytes = asRbool(CAR(args), call); args = CDR(args);
1284+
invert = asRbool(CAR(args), call);
12911285
if (fixed_opt && igcase_opt)
12921286
warning(_("argument '%s' will be ignored"), "ignore.case = TRUE");
12931287
if (fixed_opt && perl_opt) {
@@ -1573,22 +1567,17 @@ attribute_hidden SEXP do_grepraw(SEXP call, SEXP op, SEXP args, SEXP env)
15731567
offset+length it is the initial size of
15741568
the integer vector of matches */
15751569
R_size_t res_ptr, offset, i;
1576-
int igcase_opt, fixed_opt, all, value, invert;
1570+
Rboolean igcase_opt, fixed_opt, all, value, invert;
15771571

15781572
checkArity(op, args);
15791573
pat = CAR(args); args = CDR(args);
15801574
text = CAR(args); args = CDR(args);
15811575
offset = asInteger(CAR(args)); args = CDR(args);
1582-
igcase_opt = asLogical(CAR(args)); args = CDR(args);
1583-
fixed_opt = asLogical(CAR(args)); args = CDR(args);
1584-
value = asLogical(CAR(args)); args = CDR(args);
1585-
all = asLogical(CAR(args)); args = CDR(args);
1586-
invert = asLogical(CAR(args));
1587-
if (igcase_opt == NA_INTEGER) igcase_opt = 0;
1588-
if (fixed_opt == NA_INTEGER) fixed_opt = 0;
1589-
if (all == NA_INTEGER) all = 0;
1590-
if (value == NA_INTEGER) value = 0;
1591-
if (invert == NA_INTEGER) invert = 0;
1576+
igcase_opt = asRbool(CAR(args), call); args = CDR(args);
1577+
fixed_opt = asRbool(CAR(args), call); args = CDR(args);
1578+
value = asRbool(CAR(args), call); args = CDR(args);
1579+
all = asRbool(CAR(args), call); args = CDR(args);
1580+
invert = asRbool(CAR(args), call);
15921581
if (fixed_opt && igcase_opt)
15931582
warning(_("argument '%s' will be ignored"), "ignore.case = TRUE");
15941583

@@ -2106,7 +2095,8 @@ attribute_hidden SEXP do_gsub(SEXP call, SEXP op, SEXP args, SEXP env)
21062095
regmatch_t regmatch[10];
21072096
R_xlen_t i, n;
21082097
int j, ns, nns, nmatch, offset, rc;
2109-
int global, igcase_opt, perl_opt, fixed_opt, useBytes, eflags, last_end;
2098+
Rboolean global, igcase_opt, perl_opt, fixed_opt, useBytes;
2099+
int eflags, last_end;
21102100
char *u, *cbuf;
21112101
const char *spat = NULL, *srep = NULL, *s = NULL;
21122102
size_t patlen = 0, replen = 0;
@@ -2134,14 +2124,10 @@ attribute_hidden SEXP do_gsub(SEXP call, SEXP op, SEXP args, SEXP env)
21342124
pat = CAR(args); args = CDR(args);
21352125
rep = CAR(args); args = CDR(args);
21362126
text = CAR(args); args = CDR(args);
2137-
igcase_opt = asLogical(CAR(args)); args = CDR(args);
2138-
perl_opt = asLogical(CAR(args)); args = CDR(args);
2139-
fixed_opt = asLogical(CAR(args)); args = CDR(args);
2140-
useBytes = asLogical(CAR(args)); args = CDR(args);
2141-
if (igcase_opt == NA_INTEGER) igcase_opt = 0;
2142-
if (perl_opt == NA_INTEGER) perl_opt = 0;
2143-
if (fixed_opt == NA_INTEGER) fixed_opt = 0;
2144-
if (useBytes == NA_INTEGER) useBytes = 0;
2127+
igcase_opt = asRbool(CAR(args), call); args = CDR(args);
2128+
perl_opt = asRbool(CAR(args), call); args = CDR(args);
2129+
fixed_opt = asRbool(CAR(args), call); args = CDR(args);
2130+
useBytes = asRbool(CAR(args), call); args = CDR(args);
21452131
if (fixed_opt && igcase_opt)
21462132
warning(_("argument '%s' will be ignored"), "ignore.case = TRUE");
21472133
if (fixed_opt && perl_opt) {

0 commit comments

Comments
 (0)