From b748eae03558aad2134defbecc4fadd40e3bd013 Mon Sep 17 00:00:00 2001 From: Santiago Lapresta Date: Tue, 20 May 2014 16:54:50 +0200 Subject: [PATCH] Added `in` command --- builtin.c | 1 + docs/content/3.manual/manual.yml | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/builtin.c b/builtin.c index dc355353..eaa7a842 100644 --- a/builtin.c +++ b/builtin.c @@ -1111,6 +1111,7 @@ static const char* const jq_builtins[] = { " | reduce range(0; $max) as $j" " ([]; . + [reduce range(0;$length) as $i ([]; . + [ $in[$i][$j] ] )] )" " end;", + "def in(xs): . as $x | xs | contains($x)", }; #undef LIBM_DD diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml index 42c6c98c..aa8a4e2c 100644 --- a/docs/content/3.manual/manual.yml +++ b/docs/content/3.manual/manual.yml @@ -1168,6 +1168,30 @@ sections: input: '"a,b, cd, efg, hijk"' output: ['12'] + - title: `in` + body: | + + The filter `in(b)` will produce true if the input is + completely contained within b. It is, essentially, an + inversed version of `contains`. + + examples: + - program: 'in("foobar")' + input: '"bar"' + output: ['true'] + - program: 'in(["foobar", "foobaz", "blarp"])' + input: '["baz", "bar"]' + output: ['true'] + - program: 'in(["foobar", "foobaz", "blarp"])' + input: '["bazzzzz", "bar"]' + output: ['false'] + - program: 'in({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})' + input: '{foo: 12, bar: [{barp: 12}]}' + output: ['true'] + - program: 'in({"foo": 12, "bar":[1,2,{"barp":12, "blip":13}]})' + input: '{foo: 12, bar: [{barp: 15}]}' + output: ['false'] + - title: "`startswith(str)`" body: |