HWLDFWordAccumulator.php in Drupal 8
File
core/lib/Drupal/Component/Diff/Engine/HWLDFWordAccumulator.php
View source
<?php
namespace Drupal\Component\Diff\Engine;
class HWLDFWordAccumulator {
const NBSP = ' ';
protected $lines = [];
protected $line = '';
protected $group = '';
protected $tag = '';
protected function _flushGroup($new_tag) {
if ($this->group !== '') {
if ($this->tag == 'mark') {
$this->line = $this->line . '<span class="diffchange">' . $this->group . '</span>';
}
else {
$this->line = $this->line . $this->group;
}
}
$this->group = '';
$this->tag = $new_tag;
}
protected function _flushLine($new_tag) {
$this
->_flushGroup($new_tag);
if ($this->line != '') {
array_push($this->lines, $this->line);
}
else {
array_push($this->lines, $this::NBSP);
}
$this->line = '';
}
public function addWords($words, $tag = '') {
if ($tag != $this->tag) {
$this
->_flushGroup($tag);
}
foreach ($words as $word) {
if ($word == '') {
continue;
}
if ($word[0] == "\n") {
$this
->_flushLine($tag);
$word = mb_substr($word, 1);
}
assert(!strstr($word, "\n"));
$this->group .= $word;
}
}
public function getLines() {
$this
->_flushLine('~done');
return $this->lines;
}
}