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

Breadcrumb

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

function UnicodeString::splice

Overrides AbstractString::splice

File

vendor/symfony/string/UnicodeString.php, line 284

Class

UnicodeString
Represents a string of Unicode grapheme clusters encoded as UTF-8.

Namespace

Symfony\Component\String

Code

public function splice(string $replacement, int $start = 0, ?int $length = null) : static {
    $str = clone $this;
    $start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
    $length = $length ? \strlen(grapheme_substr($this->string, $start, $length)) : $length;
    $str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
    if (normalizer_is_normalized($str->string)) {
        return $str;
    }
    if (false === ($string = normalizer_normalize($str->string))) {
        throw new InvalidArgumentException('Invalid UTF-8 string.');
    }
    $str->string = $string;
    return $str;
}
RSS feed
Powered by Drupal