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 b56160e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions docs/content/manual/dev/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion docs/content/manual/v1.7/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 é"']

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:
split(" ") | map(sub("(?<a>.)"; "\(.a|ascii_upcase)")) | join(" ")

# Streaming utilities
def truncate_stream(stream):
Expand Down

0 comments on commit b56160e

Please sign in to comment.