| @@ 339-349 (lines=11) @@ | ||
| 336 | * |
|
| 337 | * @return MapInterface<int, self> |
|
| 338 | */ |
|
| 339 | public function words(string $charlist = ''): MapInterface |
|
| 340 | { |
|
| 341 | $words = str_word_count($this->value, 2, $charlist); |
|
| 342 | $map = new Map('int', self::class); |
|
| 343 | ||
| 344 | foreach ($words as $position => $word) { |
|
| 345 | $map = $map->put($position, new self($word, $this->encoding)); |
|
| 346 | } |
|
| 347 | ||
| 348 | return $map; |
|
| 349 | } |
|
| 350 | ||
| 351 | /** |
|
| 352 | * Split the string using a regular expression |
|
| @@ 359-369 (lines=11) @@ | ||
| 356 | * |
|
| 357 | * @return StreamInterface<self> |
|
| 358 | */ |
|
| 359 | public function pregSplit(string $regex, int $limit = -1): StreamInterface |
|
| 360 | { |
|
| 361 | $strings = preg_split($regex, $this->value, $limit); |
|
| 362 | $stream = new Stream(self::class); |
|
| 363 | ||
| 364 | foreach ($strings as $string) { |
|
| 365 | $stream = $stream->add(new self($string, $this->encoding)); |
|
| 366 | } |
|
| 367 | ||
| 368 | return $stream; |
|
| 369 | } |
|
| 370 | ||
| 371 | /** |
|
| 372 | * Check if the string match the given regular expression |
|