You are here

function DrupalDiffInline::process_edits in Diff 7.3

Same name and namespace in other branches
  1. 6.2 DiffEngine.php \DrupalDiffInline::process_edits()
  2. 7.2 DiffEngine.php \DrupalDiffInline::process_edits()

Merge copy and equivalent edits into intelligible chunks.

1 call to DrupalDiffInline::process_edits()
DrupalDiffInline::render in ./DiffEngine.php
Render differences inline using HTML markup.

File

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

Class

DrupalDiffInline
Drupal inline Diff formatter. @private @subpackage DifferenceEngine

Code

function process_edits($edits) {
  $processed = array();
  $current = array_shift($edits);

  // Make two passes -- first merge space delimiter copies back into their originals.
  while ($chunk = array_shift($edits)) {
    if ($chunk->type == 'copy' && $chunk->orig === array(
      ' ',
    )) {
      $current->orig = array_merge((array) $current->orig, (array) $chunk->orig);
      $current->closing = array_merge((array) $current->closing, (array) $chunk->closing);
    }
    else {
      $processed[] = $current;
      $current = $chunk;
    }
  }
  $processed[] = $current;

  // Initial setup
  $edits = $processed;
  $processed = array();
  $current = array_shift($edits);

  // Second, merge equivalent chunks into each other.
  while ($chunk = array_shift($edits)) {
    if ($current->type == $chunk->type) {
      $current->orig = array_merge((array) $current->orig, (array) $chunk->orig);
      $current->closing = array_merge((array) $current->closing, (array) $chunk->closing);
    }
    else {
      $processed[] = $current;
      $current = $chunk;
    }
  }
  $processed[] = $current;
  return $processed;
}