class HWLDFWordAccumulator
Same name in other branches
- 9 core/lib/Drupal/Component/Diff/Engine/HWLDFWordAccumulator.php \Drupal\Component\Diff\Engine\HWLDFWordAccumulator
- 8.9.x core/lib/Drupal/Component/Diff/Engine/HWLDFWordAccumulator.php \Drupal\Component\Diff\Engine\HWLDFWordAccumulator
- 10 core/lib/Drupal/Component/Diff/Engine/HWLDFWordAccumulator.php \Drupal\Component\Diff\Engine\HWLDFWordAccumulator
@todo document @private @subpackage DifferenceEngine
Hierarchy
- class \Drupal\Component\Diff\Engine\HWLDFWordAccumulator
Expanded class hierarchy of HWLDFWordAccumulator
2 files declare their use of HWLDFWordAccumulator
- HWLDFWordAccumulatorTest.php in core/
tests/ Drupal/ Tests/ Component/ Diff/ Engine/ HWLDFWordAccumulatorTest.php - WordLevelDiff.php in core/
lib/ Drupal/ Component/ Diff/ WordLevelDiff.php
File
-
core/
lib/ Drupal/ Component/ Diff/ Engine/ HWLDFWordAccumulator.php, line 14
Namespace
Drupal\Component\Diff\EngineView source
class HWLDFWordAccumulator {
/**
* An iso-8859-x non-breaking space.
*/
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 {
// make empty lines visible by inserting an NBSP
array_push($this->lines, $this::NBSP);
}
$this->line = '';
}
public function addWords($words, $tag = '') {
if ($tag != $this->tag) {
$this->_flushGroup($tag);
}
foreach ($words as $word) {
// new-line should only come as first char of word.
if ($word == '') {
continue;
}
if ($word[0] == "\n") {
$this->_flushLine($tag);
$word = mb_substr($word, 1);
}
assert(!str_contains($word, "\n"));
$this->group .= $word;
}
}
public function getLines() {
$this->_flushLine('~done');
return $this->lines;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
HWLDFWordAccumulator::$group | protected | property | |
HWLDFWordAccumulator::$line | protected | property | |
HWLDFWordAccumulator::$lines | protected | property | |
HWLDFWordAccumulator::$tag | protected | property | |
HWLDFWordAccumulator::addWords | public | function | |
HWLDFWordAccumulator::getLines | public | function | |
HWLDFWordAccumulator::NBSP | constant | An iso-8859-x non-breaking space. | |
HWLDFWordAccumulator::_flushGroup | protected | function | |
HWLDFWordAccumulator::_flushLine | protected | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.