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: functions/find_first.yml
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -19,12 +19,14 @@ returns:
19
19
type: number
20
20
desc: ''
21
21
desc: |
22
-
Given the `subject` string, `find_first()` returns the index of the first occurence where the `sub` substring appears in `subject` or `null`.
22
+
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.
23
23
24
-
The `start` and `end` parameters are optional and allow to select where `find_first()` must perform its search within `subject`.
24
+
The `start` and `end` parameters are optional and allow restricting the range within `subject` in which `sub` must be found.
25
25
26
-
* If `start` is omitted, it defaults to `0` which is the start of the `subject` string.
27
-
* If `end` is omitted, it defaults to `length(subject) - 1` which is is the end of the `subject` string.
26
+
* If `start` is omitted, it defaults to `0` (which is the start of the `subject` string).
27
+
* If `end` is omitted, it defaults to `length(subject) - 1` (which is is the end of the `subject` string).
28
+
29
+
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.
Copy file name to clipboardExpand all lines: functions/find_last.yml
+6-5Lines changed: 6 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -16,11 +16,12 @@ returns:
16
16
type: number
17
17
desc: ''
18
18
desc: |
19
-
Given the `subject` string, `find_last()` returns the index of the last occurence where the `sub` substring appears in `subject` or `null`.
19
+
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.
20
20
21
-
The `pos` parameter is optional and allow to select where `find_first()` must perform its search within `subject`.
22
-
If this is parameter omitted, it defaults to `length(subject) - 1` which is is the end of the `subject` string.
23
-
`find_last()` then searches backwards in the `subject` string for the first occurrence of the `sub` substring.
21
+
The `pos` parameter is optional and allows restricting the maximum index within `subject` at which to search for `sub`.
22
+
If this is parameter omitted, it defaults to `length(subject) - 1` (which is is the end of the `subject` string).
23
+
24
+
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.
Copy file name to clipboardExpand all lines: jep-014-string-functions.md
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,14 +19,14 @@ This JEP introduces a core set of useful string manipulation functions. Those fu
19
19
```
20
20
int find_first(string $subject, string $sub[, int $start[, int $end]])
21
21
```
22
-
Given the `$subject` string, `find_first()` returns the index of the first occurence where the `$sub` substring appears in `$subject` or `null`.
22
+
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.
23
23
24
-
The `$start` and `$end` parameters are optional and allow to select where `find_first()` must perform its search within `$subject`.
24
+
The `$start` and `$end` parameters are optional and allow restricting the range within `$subject` in which `$sub` must be found.
25
25
26
-
- If `$start` is omitted, it defaults to `0` which is the start of the `$subject` string.
27
-
- If `$end` is omitted, it defaults to `length($subject) -1` which is the end of the string.
26
+
- If `$start` is omitted, it defaults to `0`(which is the start of the `$subject` string).
27
+
- If `$end` is omitted, it defaults to `length(subject) -1`(which is is the end of the `$subject`string).
28
28
29
-
Contrary to similar functions found in most popular programming languages, the `find_first()` function does not return `-1` if the occurrence of the `$sub`substring cannot be found. Instead, it returns `null` for consistency reasons with how JMESPath behaves.
29
+
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.
30
30
31
31
### Examples
32
32
@@ -47,13 +47,12 @@ Contrary to similar functions found in most popular programming languages, the `
47
47
```
48
48
int find_last(string $subject, string $sub[, int $pos])
49
49
```
50
-
Given the `$subject` string, `find_last()` returns the index of the last occurence where the `$sub` substring appears in `$subject` or `null`.
50
+
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.
51
51
52
-
The `$pos` optional parameter allow to select where `find_last()` must perform its search within `$subject`.
52
+
The `$pos` parameter is optional and allows restricting the maximum index within `$subject` at which to search for `$sub`.
53
+
If this is parameter omitted, it defaults to `length(subject) - 1` (which is is the end of the `$subject` string).
53
54
54
-
If this parameter is omitted, It defaults to `length($subject) - 1` which is the end of the `$subject` string. `find_last()` then searches backwards in the `$subject` string for the first occurrence of `$sub`.
55
-
56
-
Likewise, the `find_last()` function does not return `-1` if the occurrence of the `$sub` substring cannot be found. Instead, it returns `null` for consistency reasons with how JMESPath behaves.
55
+
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.
57
56
58
57
| Given | Expression | Result
59
58
|---|---|---
@@ -82,11 +81,13 @@ Returns the lowercase `$subject` string.
82
81
string pad_left(string $subject, number $width[, string $pad])
83
82
```
84
83
85
-
Given the `$subject` string, `pad_left()` adds `$width - length($subject)`characters to the beginning of the string and returns a string of length `$width`.
84
+
Given the `$subject` string, `pad_left()` adds characters to the beginning and returns a string of length at least`$width`.
86
85
87
-
The `$pad` optional string parameter specifies the padding character to use. If this parameter is omitted, `pad_left()` adds one of more ASCII space characters to the beginning of the string. If present, the `$pad` string must have a single character, otherwise, an error MUST be raised.
86
+
The `$pad` optional string parameter specifies the padding character.
87
+
If omitted, it defaults to an ASCII space (U+0020).
88
+
If present, it MUST have length 1, otherwise an error MUST be raised.
88
89
89
-
The `pad_left()` function has no effect if `$width` is less than, or equal to the length of the ` $subject` string.
90
+
If the `$subject` string has length greater than or equal to `$width`, it is returned unmodified.
90
91
91
92
### Examples
92
93
@@ -103,11 +104,13 @@ The `pad_left()` function has no effect if `$width` is less than, or equal to th
103
104
string pad_right(string $subject, number $width[, string $pad])
104
105
```
105
106
106
-
Given the `$subject` string, `pad_right()` adds `$width - length($subject)`characters to the end of the string and returns a string of length `$width`.
107
+
Given the `$subject` string, `pad_right()` adds characters to the end and returns a string of length at least`$width`.
107
108
108
-
The `$pad` optional string parameter specifies the padding character to use. If this parameter is omitted, `pad_right()` adds ASCII space characters to the end of the string. If present, the `$pad` string must have a single character, otherwise, an error MUST be raised.
109
+
The `$pad` optional string parameter specifies the padding character.
110
+
If omitted, it defaults to an ASCII space (U+0020).
111
+
If present, it MUST have length 1, otherwise an error MUST be raised.
109
112
110
-
The `pad_right()` function has no effect if `$width` is less than, or equal to the length of the ` $subject` string.
113
+
If the `$subject` string has length greater than or equal to `$width`, it is returned unmodified.
111
114
112
115
### Examples
113
116
@@ -123,7 +126,7 @@ The `pad_right()` function has no effect if `$width` is less than, or equal to t
123
126
```
124
127
string replace(string $subject, string $old, string $new[, number $count])
125
128
```
126
-
Given the `$subject` string, `replace()` replaces all occurrences of the `$old` substring with the `$new` substring.
129
+
Given the `$subject` string, `replace()` replaces occurrences of the `$old` substring with the `$new` substring.
127
130
128
131
The `$count` optional parameter specifies how many occurrences of the `$old` substring in `$subject` are replaced. If this parameter is omitted, all occurrences are replaced. If `$count` is negative, an error MUST be raised.
129
132
@@ -145,11 +148,12 @@ The `replace()` function has no effect if `$count` is `0`.
145
148
array[string] split(string $subject, string $search[, number $count])
146
149
```
147
150
148
-
Given string`$subject`, `split()` breaks on occurrences of the string `$search` and returns an array.
151
+
Given the`$subject` string, `split()` breaks on ocurrences of the string `$search` and returns an array.
149
152
150
153
The `split()` function returns an array containing each partial string between occurrences of `$search`. If `$subject` contains no occurrences of the `$search` string, an array containing just the original `$subject` string will be returned.
151
154
152
-
The `$count` optional parameter specifies how many occurrences of the `$search` string are split. If this parameter is omitted, all occurrences are split. If `$count` is negative, and error MUST be raised.
155
+
The `$count` optional parameter specifies the maximum number of split points within the `$search` string.
156
+
If this parameter is omitted, all occurrences are split. If `$count` is negative, an error MUST be raised.
153
157
154
158
If `$count` is equal to `0`, `split()` returns an array containing a single element, the `$subject` string.
0 commit comments