Skip to content

Commit b56160e

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

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

docs/content/manual/dev/manual.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1856,16 +1856,19 @@ sections:
18561856
input: '["a",1,2.3,true,null,false]'
18571857
output: ['"a 1 2.3 true false"']
18581858

1859-
- title: "`ascii_downcase`, `ascii_upcase`"
1859+
- title: "`ascii_downcase`, `ascii_upcase`, `ascii_title`"
18601860
body: |
18611861
18621862
Emit a copy of the input string with its alphabetic characters (a-z and A-Z)
18631863
converted to the specified case.
18641864
18651865
examples:
1866-
- program: 'ascii_upcase'
1866+
- program: "ascii_upcase"
18671867
input: '"useful but not for é"'
18681868
output: ['"USEFUL BUT NOT FOR é"']
1869+
- program: "ascii_title"
1870+
input: '"useful but not for é"'
1871+
output: ['"Useful But Not For é"']
18691872

18701873
- title: "`while(cond; update)`"
18711874
body: |

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,7 @@ sections:
18311831
converted to the specified case.
18321832
18331833
examples:
1834-
- program: "ascii_upcase"
1834+
- program: 'ascii_upcase'
18351835
input: '"useful but not for é"'
18361836
output: ['"USEFUL BUT NOT FOR é"']
18371837

src/builtin.jq

+2
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)