Skip to content

Commit

Permalink
interp: trim: Add multi-line support
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed May 11, 2023
1 parent f254b16 commit d5ae116
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/interp/funcs.jq
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include "decode";

def intdiv(a; b): _intdiv(a; b);

def trim: capture("^\\s*(?<str>.*?)\\s*$"; "").str;
def trim: capture("^\\s*(?<str>.*?)\\s*$"; "m").str;

# does +1 and [:1] as " "*0 is null
def rpad($s; $w): . + ($s * ($w+1-length))[1:];
Expand Down
6 changes: 6 additions & 0 deletions pkg/interp/funcs.jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ streaks_by(.a)
["12"]
["12","34"]
["123","4"]

.[] | trim
["a", " abc ", "\n\t a\nb\n"]
"a"
"abc"
"a\nb"

0 comments on commit d5ae116

Please sign in to comment.