3 namespace Drupal\Component\Diff\Engine;
5 use Drupal\Component\Utility\Unicode;
8 * Additions by Axel Boldt follow, partly taken from diff.php, phpwiki-1.3.3
14 * @subpackage DifferenceEngine
16 class HWLDFWordAccumulator {
19 * An iso-8859-x non-breaking space.
21 const NBSP = ' ';
23 protected $lines = [];
27 protected $group = '';
31 protected function _flushGroup($new_tag) {
32 if ($this->group !== '') {
33 if ($this->tag == 'mark') {
34 $this->line = $this->line . '<span class="diffchange">' . $this->group . '</span>';
37 $this->line = $this->line . $this->group;
41 $this->tag = $new_tag;
44 protected function _flushLine($new_tag) {
45 $this->_flushGroup($new_tag);
46 if ($this->line != '') {
47 array_push($this->lines, $this->line);
50 // make empty lines visible by inserting an NBSP
51 array_push($this->lines, $this::NBSP);
56 public function addWords($words, $tag = '') {
57 if ($tag != $this->tag) {
58 $this->_flushGroup($tag);
60 foreach ($words as $word) {
61 // new-line should only come as first char of word.
65 if ($word[0] == "\n") {
66 $this->_flushLine($tag);
67 $word = Unicode::substr($word, 1);
69 assert(!strstr($word, "\n"));
70 $this->group .= $word;
74 public function getLines() {
75 $this->_flushLine('~done');