You are here

class _HWLDF_WordAccumulator in Diff 6.2

Same name and namespace in other branches
  1. 5.2 DiffEngine.php \_HWLDF_WordAccumulator
  2. 5 DiffEngine.php \_HWLDF_WordAccumulator
  3. 6 DiffEngine.php \_HWLDF_WordAccumulator
  4. 7.3 DiffEngine.php \_HWLDF_WordAccumulator
  5. 7.2 DiffEngine.php \_HWLDF_WordAccumulator

@todo document @private @subpackage DifferenceEngine

Hierarchy

Expanded class hierarchy of _HWLDF_WordAccumulator

File

./DiffEngine.php, line 945
A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)

View source
class _HWLDF_WordAccumulator {
  function _HWLDF_WordAccumulator() {
    $this->_lines = array();
    $this->_line = '';
    $this->_group = '';
    $this->_tag = '';
  }
  function _flushGroup($new_tag) {
    if ($this->_group !== '') {
      if ($this->_tag == 'mark') {
        $this->_line .= '<span class="diffchange">' . check_plain($this->_group) . '</span>';
      }
      else {
        $this->_line .= check_plain($this->_group);
      }
    }
    $this->_group = '';
    $this->_tag = $new_tag;
  }
  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, NBSP);
    }
    $this->_line = '';
  }
  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 = substr($word, 1);
      }
      assert(!strstr($word, "\n"));
      $this->_group .= $word;
    }
  }
  function getLines() {
    $this
      ->_flushLine('~done');
    return $this->_lines;
  }

}

Members