[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/3rdparty/diff/Diff/ -> Mapped.php (source)

   1  <?php
   2  /**
   3   * Copyright 2007-2011 Horde LLC (http://www.horde.org/)
   4   *
   5   * See the enclosed file COPYING for license information (LGPL). If you did
   6   * not receive this file, see http://www.horde.org/licenses/lgpl21.
   7   *
   8   * @package Text_Diff
   9   * @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
  10   */
  11  
  12  // Disallow direct access to this file for security reasons
  13  if(!defined("IN_MYBB"))
  14  {
  15      die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  16  }
  17  
  18  class Horde_Text_Diff_Mapped extends Horde_Text_Diff
  19  {
  20      /**
  21       * Computes a diff between sequences of strings.
  22       *
  23       * This can be used to compute things like case-insensitve diffs, or diffs
  24       * which ignore changes in white-space.
  25       *
  26       * @param array $from_lines         An array of strings.
  27       * @param array $to_lines           An array of strings.
  28       * @param array $mapped_from_lines  This array should have the same size
  29       *                                  number of elements as $from_lines.  The
  30       *                                  elements in $mapped_from_lines and
  31       *                                  $mapped_to_lines are what is actually
  32       *                                  compared when computing the diff.
  33       * @param array $mapped_to_lines    This array should have the same number
  34       *                                  of elements as $to_lines.
  35       */
  36      public function __construct($from_lines, $to_lines,
  37                                  $mapped_from_lines, $mapped_to_lines)
  38      {
  39          assert(count($from_lines) == count($mapped_from_lines));
  40          assert(count($to_lines) == count($mapped_to_lines));
  41  
  42          parent::__construct($mapped_from_lines, $mapped_to_lines);
  43  
  44          $xi = $yi = 0;
  45          for ($i = 0; $i < count($this->_edits); $i++) {
  46              $orig = &$this->_edits[$i]->orig;
  47              if (is_array($orig)) {
  48                  $orig = array_slice($from_lines, $xi, count($orig));
  49                  $xi += count($orig);
  50              }
  51  
  52              $final = &$this->_edits[$i]->final;
  53              if (is_array($final)) {
  54                  $final = array_slice($to_lines, $yi, count($final));
  55                  $yi += count($final);
  56              }
  57          }
  58      }
  59  }


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1