| @@ 349-359 (lines=11) @@ | ||
| 346 | * |
|
| 347 | * @return MapInterface<int, self> |
|
| 348 | */ |
|
| 349 | public function words(string $charlist = ''): MapInterface |
|
| 350 | { |
|
| 351 | $words = str_word_count($this->value, 2, $charlist); |
|
| 352 | $map = new Map('int', self::class); |
|
| 353 | ||
| 354 | foreach ($words as $position => $word) { |
|
| 355 | $map = $map->put($position, new self($word, $this->encoding)); |
|
| 356 | } |
|
| 357 | ||
| 358 | return $map; |
|
| 359 | } |
|
| 360 | ||
| 361 | /** |
|
| 362 | * Split the string using a regular expression |
|
| @@ 369-379 (lines=11) @@ | ||
| 366 | * |
|
| 367 | * @return StreamInterface<self> |
|
| 368 | */ |
|
| 369 | public function pregSplit(string $regex, int $limit = -1): StreamInterface |
|
| 370 | { |
|
| 371 | $strings = preg_split($regex, $this->value, $limit); |
|
| 372 | $stream = new Stream(self::class); |
|
| 373 | ||
| 374 | foreach ($strings as $string) { |
|
| 375 | $stream = $stream->add(new self($string, $this->encoding)); |
|
| 376 | } |
|
| 377 | ||
| 378 | return $stream; |
|
| 379 | } |
|
| 380 | ||
| 381 | /** |
|
| 382 | * Check if the string match the given regular expression |
|