コード例 #1
0
ファイル: WordLevelDiff.php プロジェクト: paladox/mediawiki
 /**
  * @param string[] $linesBefore
  * @param string[] $linesAfter
  */
 public function __construct($linesBefore, $linesAfter)
 {
     list($wordsBefore, $wordsBeforeStripped) = $this->split($linesBefore);
     list($wordsAfter, $wordsAfterStripped) = $this->split($linesAfter);
     try {
         parent::__construct($wordsBeforeStripped, $wordsAfterStripped);
     } catch (ComplexityException $ex) {
         // Too hard to diff, just show whole paragraph(s) as changed
         $this->edits = [new DiffOpChange($linesBefore, $linesAfter)];
     }
     $xi = $yi = 0;
     $editCount = count($this->edits);
     for ($i = 0; $i < $editCount; $i++) {
         $orig =& $this->edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($wordsBefore, $xi, count($orig));
             $xi += count($orig);
         }
         $closing =& $this->edits[$i]->closing;
         if (is_array($closing)) {
             $closing = array_slice($wordsAfter, $yi, count($closing));
             $yi += count($closing);
         }
     }
 }
コード例 #2
0
ファイル: MappedDiff.php プロジェクト: sarahwillem/OD8
 /**
  * Constructor.
  *
  * Computes diff between sequences of strings.
  *
  * This can be used to compute things like
  * case-insensitive diffs, or diffs which ignore
  * changes in white-space.
  *
  * @param $from_lines array An array of strings.
  *  (Typically these are lines from a file.)
  *
  * @param $to_lines array An array of strings.
  *
  * @param $mapped_from_lines array This array should
  *  have the same size number of elements as $from_lines.
  *  The elements in $mapped_from_lines and
  *  $mapped_to_lines are what is actually compared
  *  when computing the diff.
  *
  * @param $mapped_to_lines array This array should
  *  have the same number of elements as $to_lines.
  */
 public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 {
     assert(sizeof($from_lines) == sizeof($mapped_from_lines));
     assert(sizeof($to_lines) == sizeof($mapped_to_lines));
     parent::__construct($mapped_from_lines, $mapped_to_lines);
     $xi = $yi = 0;
     for ($i = 0; $i < sizeof($this->edits); $i++) {
         $orig =& $this->edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($from_lines, $xi, sizeof($orig));
             $xi += sizeof($orig);
         }
         $closing =& $this->edits[$i]->closing;
         if (is_array($closing)) {
             $closing = array_slice($to_lines, $yi, sizeof($closing));
             $yi += sizeof($closing);
         }
     }
 }
コード例 #3
0
 /**
  * @param string[] $linesBefore
  * @param string[] $linesAfter
  */
 public function __construct($linesBefore, $linesAfter)
 {
     list($wordsBefore, $wordsBeforeStripped) = $this->split($linesBefore);
     list($wordsAfter, $wordsAfterStripped) = $this->split($linesAfter);
     parent::__construct($wordsBeforeStripped, $wordsAfterStripped);
     $xi = $yi = 0;
     $editCount = count($this->edits);
     for ($i = 0; $i < $editCount; $i++) {
         $orig =& $this->edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($wordsBefore, $xi, count($orig));
             $xi += count($orig);
         }
         $closing =& $this->edits[$i]->closing;
         if (is_array($closing)) {
             $closing = array_slice($wordsAfter, $yi, count($closing));
             $yi += count($closing);
         }
     }
 }
コード例 #4
0
ファイル: DairikiDiff.php プロジェクト: whysasse/kmwiki
 /**
  * Constructor.
  *
  * Computes diff between sequences of strings.
  *
  * This can be used to compute things like
  * case-insensitve diffs, or diffs which ignore
  * changes in white-space.
  *
  * @param string[] $from_lines An array of strings.
  *   Typically these are lines from a file.
  * @param string[] $to_lines An array of strings.
  * @param string[] $mapped_from_lines This array should
  *   have the same size number of elements as $from_lines.
  *   The elements in $mapped_from_lines and
  *   $mapped_to_lines are what is actually compared
  *   when computing the diff.
  * @param string[] $mapped_to_lines This array should
  *   have the same number of elements as $to_lines.
  */
 public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 {
     wfProfileIn(__METHOD__);
     assert('count( $from_lines ) == count( $mapped_from_lines )');
     assert('count( $to_lines ) == count( $mapped_to_lines )');
     parent::__construct($mapped_from_lines, $mapped_to_lines);
     $xi = $yi = 0;
     $editCount = count($this->edits);
     for ($i = 0; $i < $editCount; $i++) {
         $orig =& $this->edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($from_lines, $xi, count($orig));
             $xi += count($orig);
         }
         $closing =& $this->edits[$i]->closing;
         if (is_array($closing)) {
             $closing = array_slice($to_lines, $yi, count($closing));
             $yi += count($closing);
         }
     }
     wfProfileOut(__METHOD__);
 }
コード例 #5
0
ファイル: MapDiff.php プロジェクト: SRMSE/cron-wikidata
 public function __construct(array $operations = array())
 {
     parent::__construct($operations, true);
 }
コード例 #6
0
 /**
  * Constructor.
  *
  * Computes diff between sequences of strings.
  *
  * This can be used to compute things like
  * case-insensitve diffs, or diffs which ignore
  * changes in white-space.
  *
  * @param $from_lines array An array of strings.
  *  (Typically these are lines from a file.)
  *
  * @param $to_lines array An array of strings.
  *
  * @param $mapped_from_lines array This array should
  *  have the same size number of elements as $from_lines.
  *  The elements in $mapped_from_lines and
  *  $mapped_to_lines are what is actually compared
  *  when computing the diff.
  *
  * @param $mapped_to_lines array This array should
  *  have the same number of elements as $to_lines.
  */
 public function __construct($from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 {
     assert(sizeof($from_lines) == sizeof($mapped_from_lines));
     assert(sizeof($to_lines) == sizeof($mapped_to_lines));
     parent::__construct($mapped_from_lines, $mapped_to_lines);
     $xi = $yi = 0;
     // Optimizing loop invariants:
     // http://phplens.com/lens/php-book/optimizing-debugging-php.php
     for ($i = 0, $max = sizeof($this->edits); $i < $max; $i++) {
         $orig =& $this->edits[$i]->orig;
         if (is_array($orig)) {
             $orig = array_slice($from_lines, $xi, sizeof($orig));
             $xi += sizeof($orig);
         }
         $final =& $this->edits[$i]->final;
         if (is_array($final)) {
             $final = array_slice($to_lines, $yi, sizeof($final));
             $yi += sizeof($final);
         }
     }
 }