class WordLevelDiff

@todo document @private @subpackage DifferenceEngine

Hierarchy

Expanded class hierarchy of WordLevelDiff

File

drupal/core/lib/Drupal/Component/Diff/DiffEngine.php, line 1014
A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)

View source
class WordLevelDiff extends MappedDiff {
  function MAX_LINE_LENGTH() {
    return 10000;
  }
  function WordLevelDiff($orig_lines, $closing_lines) {
    list($orig_words, $orig_stripped) = $this
      ->_split($orig_lines);
    list($closing_words, $closing_stripped) = $this
      ->_split($closing_lines);
    $this
      ->MappedDiff($orig_words, $closing_words, $orig_stripped, $closing_stripped);
  }
  function _split($lines) {
    $words = array();
    $stripped = array();
    $first = TRUE;
    foreach ($lines as $line) {

      // If the line is too long, just pretend the entire line is one big word
      // This prevents resource exhaustion problems
      if ($first) {
        $first = FALSE;
      }
      else {
        $words[] = "\n";
        $stripped[] = "\n";
      }
      if (drupal_strlen($line) > $this
        ->MAX_LINE_LENGTH()) {
        $words[] = $line;
        $stripped[] = $line;
      }
      else {
        if (preg_match_all('/ ( [^\\S\\n]+ | [0-9_A-Za-z\\x80-\\xff]+ | . ) (?: (?!< \\n) [^\\S\\n])? /xs', $line, $m)) {
          $words = array_merge($words, $m[0]);
          $stripped = array_merge($stripped, $m[1]);
        }
      }
    }
    return array(
      $words,
      $stripped,
    );
  }
  function orig() {
    $orig = new _HWLDF_WordAccumulator();
    foreach ($this->edits as $edit) {
      if ($edit->type == 'copy') {
        $orig
          ->addWords($edit->orig);
      }
      elseif ($edit->orig) {
        $orig
          ->addWords($edit->orig, 'mark');
      }
    }
    $lines = $orig
      ->getLines();
    return $lines;
  }
  function closing() {
    $closing = new _HWLDF_WordAccumulator();
    foreach ($this->edits as $edit) {
      if ($edit->type == 'copy') {
        $closing
          ->addWords($edit->closing);
      }
      elseif ($edit->closing) {
        $closing
          ->addWords($edit->closing, 'mark');
      }
    }
    $lines = $closing
      ->getLines();
    return $lines;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Diff::$edits property
Diff::Diff function Constructor. Computes diff between sequences of strings.
Diff::isEmpty function Check for empty diff.
Diff::lcs function Compute the length of the Longest Common Subsequence (LCS).
Diff::reverse function Compute reversed Diff.
Diff::_check function Check a Diff for validity.
MappedDiff::MappedDiff function Constructor.
WordLevelDiff::closing function Get the closing set of lines. Overrides Diff::closing
WordLevelDiff::MAX_LINE_LENGTH function
WordLevelDiff::orig function Get the original set of lines. Overrides Diff::orig
WordLevelDiff::WordLevelDiff function
WordLevelDiff::_split function