3 namespace Drupal\Component\Diff\Engine;
6 * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
12 * @subpackage DifferenceEngine
14 class HWLDFWordAccumulator {
17 * An iso-8859-x non-breaking space.
19 const NBSP = ' ';
21 protected $lines = [];
25 protected $group = '';
29 protected function _flushGroup($new_tag) {
30 if ($this->group !== '') {
31 if ($this->tag == 'mark') {
32 $this->line = $this->line . '<span class="diffchange">' . $this->group . '</span>';
35 $this->line = $this->line . $this->group;
39 $this->tag = $new_tag;
42 protected function _flushLine($new_tag) {
43 $this->_flushGroup($new_tag);
44 if ($this->line != '') {
45 array_push($this->lines, $this->line);
48 // make empty lines visible by inserting an NBSP
49 array_push($this->lines, $this::NBSP);
54 public function addWords($words, $tag = '') {
55 if ($tag != $this->tag) {
56 $this->_flushGroup($tag);
58 foreach ($words as $word) {
59 // new-line should only come as first char of word.
63 if ($word[0] == "\n") {
64 $this->_flushLine($tag);
65 $word = mb_substr($word, 1);
67 assert(!strstr($word, "\n"));
68 $this->group .= $word;
72 public function getLines() {
73 $this->_flushLine('~done');