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

Breadcrumb

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

function CodePointString::chunk

Overrides AbstractString::chunk

File

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

Class

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

Namespace

Symfony\Component\String

Code

public function chunk(int $length = 1) : array {
    if (1 > $length) {
        throw new InvalidArgumentException('The chunk length must be greater than zero.');
    }
    if ('' === $this->string) {
        return [];
    }
    $rx = '/(';
    while (65535 < $length) {
        $rx .= '.{65535}';
        $length -= 65535;
    }
    $rx .= '.{' . $length . '})/us';
    $str = clone $this;
    $chunks = [];
    foreach (preg_split($rx, $this->string, -1, \PREG_SPLIT_DELIM_CAPTURE | \PREG_SPLIT_NO_EMPTY) as $chunk) {
        $str->string = $chunk;
        $chunks[] = clone $str;
    }
    return $chunks;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal