function WordLevelDiff::_split

Same name in other branches
  1. 9 core/lib/Drupal/Component/Diff/WordLevelDiff.php \Drupal\Component\Diff\WordLevelDiff::_split()
  2. 8.9.x core/lib/Drupal/Component/Diff/WordLevelDiff.php \Drupal\Component\Diff\WordLevelDiff::_split()
  3. 11.x core/lib/Drupal/Component/Diff/WordLevelDiff.php \Drupal\Component\Diff\WordLevelDiff::_split()
1 call to WordLevelDiff::_split()
WordLevelDiff::__construct in core/lib/Drupal/Component/Diff/WordLevelDiff.php
Constructor.

File

core/lib/Drupal/Component/Diff/WordLevelDiff.php, line 23

Class

WordLevelDiff
@todo document @private @subpackage DifferenceEngine

Namespace

Drupal\Component\Diff

Code

protected function _split($lines) {
    $words = [];
    $stripped = [];
    $first = TRUE;
    foreach ($lines as $line) {
        // If the line is too long, just pretend the entire line is one big word
        // This prevents resource exhaustion problems
        if ($first) {
            $first = FALSE;
        }
        else {
            $words[] = "\n";
            $stripped[] = "\n";
        }
        if (mb_strlen($line) > $this::MAX_LINE_LENGTH) {
            $words[] = $line;
            $stripped[] = $line;
        }
        else {
            if (preg_match_all('/ ( [^\\S\\n]+ | [0-9_A-Za-z\\x80-\\xff]+ | . ) (?: (?!< \\n) [^\\S\\n])? /xs', $line, $m)) {
                $words = array_merge($words, $m[0]);
                $stripped = array_merge($stripped, $m[1]);
            }
        }
    }
    return [
        $words,
        $stripped,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.