Skip to content

Commit 7f3ba2f

Browse files
Adds ascii_title to string manipulation
1 parent 562d5c5 commit 7f3ba2f

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

docs/content/manual/v1.7/manual.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ sections:
18241824
input: '["a",1,2.3,true,null,false]'
18251825
output: ['"a 1 2.3 true false"']
18261826

1827-
- title: "`ascii_downcase`, `ascii_upcase`"
1827+
- title: "`ascii_downcase`, `ascii_upcase`, `ascii_title`"
18281828
body: |
18291829
18301830
Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
@@ -1834,6 +1834,9 @@ sections:
18341834
- program: "ascii_upcase"
18351835
input: '"useful but not for é"'
18361836
output: ['"USEFUL BUT NOT FOR é"']
1837+
- program: "ascii_title"
1838+
input: '"useful but not for é"'
1839+
output: ['"Useful But Not For é"']
18371840

18381841
- title: "`while(cond; update)`"
18391842
body: |

src/builtin.jq

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def ascii_downcase:
203203
# like ruby's upcase - only characters a to z are affected
204204
def ascii_upcase:
205205
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;
206+
def ascii_title:
207+
split(" ") | map(sub("(?<a>.)"; "\(.a|ascii_upcase)")) | join(" ")
206208

207209
# Streaming utilities
208210
def truncate_stream(stream):

0 commit comments

Comments
 (0)