Skip to content

Commit 262a822

Browse files
committed
Implemented trim(), trim_left() and trim_right() functions
1 parent 151dd68 commit 262a822

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

jmespath/functions.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,24 @@ def _func_replace(self, text, search, replacement, count = None):
358358
return text.replace(search, replacement, int(count))
359359
return text.replace(search, replacement)
360360

361+
@signature({'type': 'string'}, {'type': 'string', 'optional': True})
362+
def _func_trim(self, text, chars = None):
363+
if chars == None or len(chars) == 0:
364+
return text.strip()
365+
return text.strip(chars)
366+
367+
@signature({'type': 'string'}, {'type': 'string', 'optional': True})
368+
def _func_trim_left(self, text, chars = None):
369+
if chars == None or len(chars) == 0:
370+
return text.lstrip()
371+
return text.lstrip(chars)
372+
373+
@signature({'type': 'string'}, {'type': 'string', 'optional': True})
374+
def _func_trim_right(self, text, chars = None):
375+
if chars == None or len(chars) == 0:
376+
return text.rstrip()
377+
return text.rstrip(chars)
378+
361379
@signature({"types": ['object']})
362380
def _func_values(self, arg):
363381
return list(arg.values())

0 commit comments

Comments
 (0)