Skip to content

Commit 1e14f7d

Browse files
committed
src: added 'trimstr' function
1 parent a8f27cc commit 1e14f7d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/builtin.jq

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def fromdate: fromdateiso8601;
7676
def todate: todateiso8601;
7777
def ltrimstr($left): if startswith($left) then .[$left | length:] end;
7878
def rtrimstr($right): if endswith($right) then .[:$right | -length] end;
79+
def trimstr($val): ltrimstr($val)|rtrimstr($val);
7980
def match(re; mode): _match_impl(re; mode; false)|.[];
8081
def match($val): ($val|type) as $vt | if $vt == "string" then match($val; null)
8182
elif $vt == "array" and ($val | length) > 1 then match($val[0]; $val[1])

tests/jq.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,10 @@ split("")
13801380
["fo", "foo", "barfoo", "foobar", "foob"]
13811381
["fo","","bar","foobar","foob"]
13821382

1383+
[.[]|trimstr("foo")]
1384+
["fo", "foo", "barfoo", "foobarfoo", "foob"]
1385+
["fo","","bar","bar","b"]
1386+
13831387
[(index(","), rindex(",")), indices(",")]
13841388
"a,bc,def,ghij,klmno"
13851389
[1,13,[1,4,8,13]]

0 commit comments

Comments
 (0)