Skip to content

Commit

Permalink
Adds ascii_title to string manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomatavelli committed Oct 19, 2024
1 parent 562d5c5 commit c70ab3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/content/manual/v1.7/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ 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)
Expand All @@ -1834,6 +1834,9 @@ sections:
- 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: |
Expand Down
2 changes: 2 additions & 0 deletions src/builtin.jq
Original file line number Diff line number Diff line change
Expand Up @@ -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:
ascii_downcase | split(" ") | map(sub("(?<a>.)"; "\(.a|ascii_upcase)")) | join(" ")

# Streaming utilities
def truncate_stream(stream):
Expand Down

0 comments on commit c70ab3c

Please sign in to comment.