Skip to content

Commit 151dd68

Browse files
committed
Implemented find_first() function
find_first()
1 parent fcbba74 commit 151dd68

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jmespath/functions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,17 @@ def _func_keys(self, arg):
308308
# should we also return the indices of a list?
309309
return list(arg.keys())
310310

311+
@signature(
312+
{'type': 'string'},
313+
{'type': 'string'},
314+
{'type': 'number', 'optional': True},
315+
{'type': 'number', 'optional': True})
316+
def _func_find_first(self, text, search, start = 0, end = -1):
317+
if end == -1:
318+
end = len(text)
319+
pos = text.find(search, start, end)
320+
return pos if pos != -1 else None
321+
311322
@signature(
312323
{'type': 'string'},
313324
{'type': 'number'},

0 commit comments

Comments
 (0)