Skip to content

Commit

Permalink
filterx: implement isset/unset at FilterXGetSubscript
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi committed Apr 9, 2024
1 parent 652a0cd commit 000d391
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/filterx/expr-get-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,51 @@ _eval(FilterXExpr *s)
return result;
}

static gboolean
_isset(FilterXExpr *s)
{
FilterXGetSubscript *self = (FilterXGetSubscript *) s;
FilterXObject *variable = filterx_expr_eval_typed(self->operand);
if (!variable)
return FALSE;

FilterXObject *key = filterx_expr_eval_typed(self->key);
if (!key)
{
filterx_object_unref(variable);
return FALSE;
}

gboolean result = filterx_object_is_key_set(variable, key);

filterx_object_unref(key);
filterx_object_unref(variable);
return result;
}

static gboolean
_unset(FilterXExpr *s)
{
FilterXGetSubscript *self = (FilterXGetSubscript *) s;

FilterXObject *variable = filterx_expr_eval_typed(self->operand);
if (!variable)
return FALSE;

FilterXObject *key = filterx_expr_eval_typed(self->key);
if (!key)
{
filterx_object_unref(variable);
return FALSE;
}

gboolean result = filterx_object_unset_key(variable, key);

filterx_object_unref(key);
filterx_object_unref(variable);
return result;
}

static void
_free(FilterXExpr *s)
{
Expand All @@ -65,6 +110,8 @@ filterx_get_subscript_new(FilterXExpr *operand, FilterXExpr *key)

filterx_expr_init_instance(&self->super);
self->super.eval = _eval;
self->super.isset = _isset;
self->super.unset = _unset;
self->super.free_fn = _free;
self->operand = operand;
self->key = key;
Expand Down

0 comments on commit 000d391

Please sign in to comment.