You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jep-014-string-functions.md
+21-12Lines changed: 21 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,9 @@ _Functions can ~~either~~ have a specific arity, **a range of valid – minimum
25
25
```
26
26
int find_first(string $subject, string $sub[, int $start[, int $end]])
27
27
```
28
-
Given the `$subject` string, `find_first()` returns the zero-based index of the first occurence where the `$sub` substring appears in `$subject` or `null` if it does not appear.
28
+
Given the `$subject` string, `find_first()` returns the zero-based index of the first occurence where the `$sub` substring appears in `$subject` or `null` if it does not appear. If either the `$subject` or the `$sub` argument is an empty string, `find_first()` returns `null`.
29
29
30
-
The `$start` and `$end` parameters are optional and allow restricting the range within `$subject` in which `$sub` must be found.
30
+
The `$start` and `$end` parameters are optional and allow restricting to the slice `[$start:$end]`the range within `$subject` in which `$sub` must be found.
31
31
32
32
- If `$start` is omitted, it defaults to `0` (which is the start of the `$subject` string).
33
33
- If `$end` is omitted, it defaults to `length(subject)` (which is past the end of the `$subject` string).
@@ -44,34 +44,43 @@ Contrary to similar functions found in most popular programming languages, the `
int find_last(string $subject, string $sub[, int $pos])
59
+
int find_last(string $subject, string $sub[, int $start[, int $end]])
58
60
```
59
-
Given the `$subject` string, `find_last()` returns the zero-based index of the last occurence where the `$sub` substring appears in `$subject` or `null` if it does not appear.
61
+
Given the `$subject` string, `find_last()` returns the zero-based index of the last occurence where the `$sub` substring appears in `$subject` or `null` if it does not appear. If either the `$subject` or the `$sub` argument is an empty string, `find_first()` returns `null`.
60
62
61
-
The `$pos` parameter is optional and allows restricting the maximum index within `$subject` at which to search for `$sub`.
62
-
If this is parameter omitted, it defaults to `length(subject) - 1` (which is is the end of the `$subject` string).
63
+
The `$start` and `$end` parameters are optional and allow restricting to the slice `[$start:$end]` the range within `$subject` in which `$sub` must be found.
63
64
64
-
Contrary to similar functions found in most popular programming languages, the `find_last()` function does not return `-1` if no occurrence of the substring can be found. Instead, it returns `null` for consistency reasons with how JMESPath behaves.
65
+
- If `$start` is omitted, it defaults to `0` (which is the start of the `$subject` string).
66
+
- If `$end` is omitted, it defaults to `length(subject)` (which is past the end of the `$subject` string).
67
+
68
+
If not omitted, the `$start` or `$end` arguments are expected to be integers. Otherwise, an error MUST be raised.
69
+
70
+
Contrary to similar functions found in most popular programming languages, the `find_first()` function does not return `-1` if no occurrence of the substring can be found. Instead, it returns `null` for consistency reasons with how JMESPath behaves.
0 commit comments