Skip to content

Commit a08c963

Browse files
authored
Documented split('', '') corner case (#118)
* Documented split('', '') corner case * Update jep-014-string-functions.md
1 parent 500687f commit a08c963

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

jep-014-string-functions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ Given the `$subject` string, `split()` breaks on ocurrences of the string `$sear
155155

156156
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.
157157

158+
If the `$search` argument is an empty string, `split()` breaks on every character and returns an array containing each character from the `$subject` string. Thus, if `$subject` is _also_ an empty string, `split()` returns an empty array.
159+
158160
The `$count` optional integer specifies the maximum number of split points within the `$search` string.
159161
If this parameter is omitted, all occurrences are split. If `$count` is not an integer or is negative, an error MUST be raised.
160162

@@ -168,6 +170,7 @@ Otherwise, the `split()` function breaks on occurrences of the `$search` string
168170

169171
| Expression | Result
170172
|---|---
173+
| `split('', '')` | `[]`
171174
| `split('all chars', '')` | `[ "a", "l", "l", " ", "c", "h", "a", "r", "s" ]`
172175
| `split('/', '/')` | `[ "", "" ]` |
173176
|`` split('average\|-\|min\|-\|max\|-\|mean\|-\|median', '\|-\|') `` | `[ "average", "min", "max", "mean", "median" ]`

0 commit comments

Comments
 (0)