b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_ext/phpsvnclient/ext/Diff/Diff/Engine/xdiff.php - 69 lines - 2399 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * Class used internally by Diff to actually compute the diffs.
   4   *
   5   * This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
   6   * to compute the differences between the two input arrays.
   7   *
   8   * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.4.2.5 2009/07/24 13:06:24 jan Exp $
   9   *
  10   * Copyright 2004-2009 The Horde Project (http://www.horde.org/)
  11   *
  12   * See the enclosed file COPYING for license information (LGPL). If you did
  13   * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
  14   *
  15   * @author  Jon Parise <jon@horde.org>
  16   * @package Text_Diff
  17   */
  18  if( ! defined( 'EVO_MAIN_INIT' ) ) die( 'Please, do not access this page directly.' );
  19  
  20  class Text_Diff_Engine_xdiff {
  21  
  22      /**
  23       */
  24      function diff($from_lines, $to_lines)
  25      {
  26          array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
  27          array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
  28  
  29          /* Convert the two input arrays into strings for xdiff processing. */
  30          $from_string = implode("\n", $from_lines);
  31          $to_string = implode("\n", $to_lines);
  32  
  33          /* Diff the two strings and convert the result to an array. */
  34          $diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
  35          $diff = explode("\n", $diff);
  36  
  37          /* Walk through the diff one line at a time.  We build the $edits
  38           * array of diff operations by reading the first character of the
  39           * xdiff output (which is in the "unified diff" format).
  40           *
  41           * Note that we don't have enough information to detect "changed"
  42           * lines using this approach, so we can't add Text_Diff_Op_changed
  43           * instances to the $edits array.  The result is still perfectly
  44           * valid, albeit a little less descriptive and efficient. */
  45          $edits = array();
  46          foreach ($diff as $line) {
  47              if (!strlen($line)) {
  48                  continue;
  49              }
  50              switch ($line[0]) {
  51              case ' ':
  52                  $edits[] = &new Text_Diff_Op_copy(array(substr($line, 1)));
  53                  break;
  54  
  55              case '+':
  56                  $edits[] = &new Text_Diff_Op_add(array(substr($line, 1)));
  57                  break;
  58  
  59              case '-':
  60                  $edits[] = &new Text_Diff_Op_delete(array(substr($line, 1)));
  61                  break;
  62              }
  63          }
  64  
  65          return $edits;
  66      }
  67  
  68  }
  69  ?>

title

Description

title

Description

title

Description

title

title

Body