Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CodePointString.php

function CodePointString::split

Overrides AbstractString::split

File

vendor/symfony/string/CodePointString.php, line 211

Class

CodePointString
Represents a string of Unicode code points encoded as UTF-8.

Namespace

Symfony\Component\String

Code

public function split(string $delimiter, ?int $limit = null, ?int $flags = null) : array {
    if (1 > ($limit ??= \PHP_INT_MAX)) {
        throw new InvalidArgumentException('Split limit must be a positive integer.');
    }
    if ('' === $delimiter) {
        throw new InvalidArgumentException('Split delimiter is empty.');
    }
    if (null !== $flags) {
        return parent::split($delimiter . 'u', $limit, $flags);
    }
    if (!preg_match('//u', $delimiter)) {
        throw new InvalidArgumentException('Split delimiter is not a valid UTF-8 string.');
    }
    $str = clone $this;
    $chunks = $this->ignoreCase ? preg_split('{' . preg_quote($delimiter) . '}iuD', $this->string, $limit) : explode($delimiter, $this->string, $limit);
    foreach ($chunks as &$chunk) {
        $str->string = $chunk;
        $chunk = clone $str;
    }
    return $chunks;
}
RSS feed
Powered by Drupal