function DrupalDiffInline::process_edits

Merge copy and equivalent edits into intelligible chunks.

1 call to DrupalDiffInline::process_edits()
DrupalDiffInline::render in drupal/core/lib/Drupal/Component/Diff/DiffEngine.php
Render differences inline using HTML markup.

File

drupal/core/lib/Drupal/Component/Diff/DiffEngine.php, line 1312
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;
}