src/CharacterData.php
/**
     * @internal
     *
     * @see https://dom.spec.whatwg.org/#concept-cd-replace
     *
     * @throws \Rowbot\DOM\Exception\IndexSizeError If the given offset is greater than the length of the data.
     */


@throws \Rowbot\DOM\Exception\IndexSizeError If the given offset is greater than the length of the data.
@throws \ Rowbot \ DOM \ Exception \ IndexSizeError If the given offset is greater than the length of the data .
public function doReplaceData(int $offset, int $count, string $data): void
    {
        $length = $this->getLength();
        if ($offset < 0 || $offset > $length) {
            throw new IndexSizeError(sprintf(
                'The offset should be less than the length of the data. The'
                . 'offset given is %d and the length of the data is %d.',
                $offset,
                $length
            ));
        }
        if ($offset + $count > $length) {
            $count = $length - $offset;
        }
        $this->data = mb_substr($this->data, 0, $offset, 'utf-8')
            . $data
            . mb_substr($this->data, $offset + $count, $length - $offset, 'utf-8');
        $newDataLen = mb_strlen($data, 'utf-8');
        $ranges = [];
        foreach (Range::getRangeCollection() as $range) {
            $startNode = $range->startContainer;
            $endNode = $range->endContainer;
            if ($startNode === $this || $endNode === $this) {
                $ranges[] = [$range, $startNode, $endNode];
            }
        }
        foreach ($ranges as [$range, $startNode, $endNode]) {
            $startOffset = $range->startOffset;
            if (
                $startNode === $this
                && $startOffset > $offset
                && $startOffset <= $offset + $count
            ) {
                $range->setStartInternal($startNode, $offset);
            }
        }
        foreach ($ranges as [$range, $startNode, $endNode]) {
            $endOffset = $range->endOffset;
            if (
                $endNode === $this
                && $endOffset > $offset
                && $endOffset <= $offset + $count
            ) {
                $range->setEndInternal($endNode, $offset);
            }
        }
        foreach ($ranges as [$range, $startNode, $endNode]) {
            $startOffset = $range->startOffset;
            if ($startNode === $this && $startOffset > $offset + $count) {
                $range->setStartInternal($startNode, $startOffset + $newDataLen - $count);
            }
        }
        foreach ($ranges as [$range, $startNode, $endNode]) {
            $endOffset = $range->endOffset;
            if ($endNode === $this && $endOffset > $offset + $count) {
                $range->setEndInternal($endNode, $endOffset + $newDataLen - $count);
            }
        }
        unset($ranges);
    }
public function doReplaceData ( int $ offset , int $ count , string $ data ) : void { $ length = $ this -> getLength ( ) ; if ( $ offset < 0 || $ offset > $ length ) { throw new IndexSizeError ( sprintf ( 'The offset should be less than the length of the data. The' . 'offset given is %d and the length of the data is %d.' , $ offset , $ length ) ) ; } if ( $ offset + $ count > $ length ) { $ count = $ length - $ offset ; } $ this -> data = mb_substr ( $ this -> data , 0 , $ offset , 'utf-8' ) . $ data . mb_substr ( $ this -> data , $ offset + $ count , $ length - $ offset , 'utf-8' ) ; $ newDataLen = mb_strlen ( $ data , 'utf-8' ) ; $ ranges = [ ] ; foreach ( Range :: getRangeCollection ( ) as $ range ) { $ startNode = $ range -> startContainer ; $ endNode = $ range -> endContainer ; if ( $ startNode === $ this || $ endNode === $ this ) { $ ranges [ ] = [ $ range , $ startNode , $ endNode ] ; } } foreach ( $ ranges as [ $ range , $ startNode , $ endNode ] ) { $ startOffset = $ range -> startOffset ; if ( $ startNode === $ this && $ startOffset > $ offset && $ startOffset <= $ offset + $ count ) { $ range -> setStartInternal ( $ startNode , $ offset ) ; } } foreach ( $ ranges as [ $ range , $ startNode , $ endNode ] ) { $ endOffset = $ range -> endOffset ; if ( $ endNode === $ this && $ endOffset > $ offset && $ endOffset <= $ offset + $ count ) { $ range -> setEndInternal ( $ endNode , $ offset ) ; } } foreach ( $ ranges as [ $ range , $ startNode , $ endNode ] ) { $ startOffset = $ range -> startOffset ; if ( $ startNode === $ this && $ startOffset > $ offset + $ count ) { $ range -> setStartInternal ( $ startNode , $ startOffset + $ newDataLen - $ count ) ; } } foreach ( $ ranges as [ $ range , $ startNode , $ endNode ] ) { $ endOffset = $ range -> endOffset ; if ( $ endNode === $ this && $ endOffset > $ offset + $ count ) { $ range -> setEndInternal ( $ endNode , $ endOffset + $ newDataLen - $ count ) ; } } unset ( $ ranges ) ; }
@internal
 @see https://dom.spec.whatwg.org/#concept-cd-replace
@internal @see https : // dom . spec . whatwg . org / #concept - cd - replace
// TODO: Queue a mutation record of "characterData" for node with // oldValue node’s data.