From b56160e3a3a7340ccec5ddb960dd0faaa19d59d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fa=CC=81bio=20Matavelli?= Date: Sat, 19 Oct 2024 12:06:32 +0100 Subject: [PATCH] Adds ascii_title to string manipulation --- docs/content/manual/dev/manual.yml | 7 +++++-- docs/content/manual/v1.7/manual.yml | 2 +- src/builtin.jq | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/content/manual/dev/manual.yml b/docs/content/manual/dev/manual.yml index 60debde5e5..a9f8f93432 100644 --- a/docs/content/manual/dev/manual.yml +++ b/docs/content/manual/dev/manual.yml @@ -1856,16 +1856,19 @@ sections: input: '["a",1,2.3,true,null,false]' output: ['"a 1 2.3 true false"'] - - title: "`ascii_downcase`, `ascii_upcase`" + - title: "`ascii_downcase`, `ascii_upcase`, `ascii_title`" body: | Emit a copy of the input string with its alphabetic characters (a-z and A-Z) converted to the specified case. examples: - - program: 'ascii_upcase' + - program: "ascii_upcase" input: '"useful but not for é"' output: ['"USEFUL BUT NOT FOR é"'] + - program: "ascii_title" + input: '"useful but not for é"' + output: ['"Useful But Not For é"'] - title: "`while(cond; update)`" body: | diff --git a/docs/content/manual/v1.7/manual.yml b/docs/content/manual/v1.7/manual.yml index 06e63aa7a0..600acea698 100644 --- a/docs/content/manual/v1.7/manual.yml +++ b/docs/content/manual/v1.7/manual.yml @@ -1831,7 +1831,7 @@ sections: converted to the specified case. examples: - - program: "ascii_upcase" + - program: 'ascii_upcase' input: '"useful but not for é"' output: ['"USEFUL BUT NOT FOR é"'] diff --git a/src/builtin.jq b/src/builtin.jq index 0d1d6774ab..01abdb5eec 100644 --- a/src/builtin.jq +++ b/src/builtin.jq @@ -203,6 +203,8 @@ def ascii_downcase: # 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; +def ascii_title: + split(" ") | map(sub("(?.)"; "\(.a|ascii_upcase)")) | join(" ") # Streaming utilities def truncate_stream(stream):