summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Lapresta <santiago.lapresta@gmail.com>2014-05-20 16:54:50 +0200
committerSantiago Lapresta <santiago.lapresta@gmail.com>2014-12-22 22:14:06 +0100
commitb748eae03558aad2134defbecc4fadd40e3bd013 (patch)
tree0e6f155b1550c9c921c7d90e894936b59a9be186
parent54a0470c4262711e3897355906906160aab16752 (diff)
Added `in` command
-rw-r--r--builtin.c1
-rw-r--r--docs/content/3.manual/manual.yml24
2 files changed, 25 insertions, 0 deletions
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: |