summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkoppstein <pkoppstein@gmail.com>2014-10-06 22:51:13 -0400
committerNicolas Williams <nico@cryptonector.com>2014-12-27 18:38:52 -0600
commit56344670f4aea8bedb5bbbab55c28918fa9224a8 (patch)
tree92295991c1debacbfe5d0ea385e701e73cc8e527
parent5df20f4954a5d3c2b2b1086bf758c1c9e7f3a61d (diff)
ascii_upcase/0 and ascii_downcase/0
-rw-r--r--builtin.c6
-rw-r--r--docs/content/3.manual/manual.yml12
-rw-r--r--tests/all.test4
3 files changed, 22 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 105290ca..c9b1868f 100644
--- a/builtin.c
+++ b/builtin.c
@@ -1155,6 +1155,12 @@ static const char* const jq_builtins[] = {
" exp, _repeat;"
" try _repeat catch if .==\"break\" then empty else . end;",
"def inputs: repeat(_input);",
+ // # like ruby's downcase - only characters A to Z are affected
+ "def ascii_downcase:"
+ " explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;",
+ // # like ruby's upcase - only characters a to z are affected
+ "def ascii_upcase:"
+ " explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;",
};
#undef LIBM_DD
diff --git a/docs/content/3.manual/manual.yml b/docs/content/3.manual/manual.yml
index 5e4467c4..cfd87c24 100644
--- a/docs/content/3.manual/manual.yml
+++ b/docs/content/3.manual/manual.yml
@@ -1312,6 +1312,18 @@ sections:
input: '["a","b,c,d","e"]'
output: ['"a, b,c,d, e"']
+
+ - title: "`ascii_downcase`, `ascii_upcase`"
+ body: |
+
+ Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
+ converted to the specified case.
+
+ example:
+ - program: 'ascii_upcase'
+ input: '"useful but not for é"'
+ output: '"USEFUL BUT NOT FOR é"'
+
- title: "`while(cond; update)`"
body: |
diff --git a/tests/all.test b/tests/all.test
index e91810f0..f632e43e 100644
--- a/tests/all.test
+++ b/tests/all.test
@@ -1107,3 +1107,7 @@ flatten(2)
transpose
[[1], [2,3]]
[[1,2],[null,3]]
+
+ascii_upcase
+"useful but not for é"
+"USEFUL BUT NOT FOR é"