[augeas-devel] [PATCH 3/3] Add support for an 'i' flag in regexp builtin function
David Lutterkort
lutter at redhat.com
Wed Aug 1 19:45:42 UTC 2012
On Wed, 2012-08-01 at 09:15 +0200, Raphaël Pinson wrote:
> ---
> src/internal.h | 3 ++-
> src/pathx.c | 39 +++++++++++++++++++++++++++++++--------
> 2 files changed, 33 insertions(+), 9 deletions(-)
ACK after fixing
> diff --git a/src/pathx.c b/src/pathx.c
> index c51f7e4..66a15ad 100644
> --- a/src/pathx.c
> +++ b/src/pathx.c
> @@ -283,12 +284,15 @@ static void func_position(struct state *state, int nargs);
> static void func_count(struct state *state, int nargs);
> static void func_label(struct state *state, int nargs);
> static void func_regexp(struct state *state, int nargs);
> +static void func_regexp_flag(struct state *state, int nargs);
You don't need a new func here; you can use func_regexp for both the one
and two argument case.
> static void func_glob(struct state *state, int nargs);
> static void func_int(struct state *state, int nargs);
>
> static const enum type const arg_types_nodeset[] = { T_NODESET };
> static const enum type const arg_types_string[] = { T_STRING };
> static const enum type const arg_types_bool[] = { T_BOOLEAN };
> +static const enum type const arg_types_string_string[] = { T_STRING, T_STRING };
> +static const enum type const arg_types_nodeset_string[] = { T_STRING, T_STRING };
That first entry in the array should be T_NODESET - which means we also
need a test for passing a nodeset to regexp
> @@ -780,12 +790,25 @@ static void func_regexp_or_glob(struct state *state, int glob) {
>
> static void func_regexp(struct state *state, int nargs) {
> ensure_arity(1, 1);
> - func_regexp_or_glob(state, 0);
> + func_regexp_or_glob(state, 0, 0);
> +}
Something like this should work (also allow "" as a flag):
static void func_regexp(struct state *state, int nargs) {
int nocase = 0;
ensure_arity(1, 2);
if (nargs == 2) {
struct value *f = pop_value(state);
if (STREQ("i", f->string))
nocase = 1;
else if (STRNEQ("", f->string))
STATE_ERROR(state, PATHX_EREGEXPFLAG);
}
func_regexp_or_glob(state, 0, nocase);
}
David
More information about the augeas-devel
mailing list