wp/wp-includes/Text/Diff.php
changeset 7 cf61fcea0001
parent 0 d970ebf37754
child 18 be944660c56a
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    31      *                           will automatically select the best.
    31      *                           will automatically select the best.
    32      * @param array $params      Parameters to pass to the diffing engine.
    32      * @param array $params      Parameters to pass to the diffing engine.
    33      *                           Normally an array of two arrays, each
    33      *                           Normally an array of two arrays, each
    34      *                           containing the lines from a file.
    34      *                           containing the lines from a file.
    35      */
    35      */
    36     function Text_Diff($engine, $params)
    36     function __construct( $engine, $params )
    37     {
    37     {
    38         // Backward compatibility workaround.
    38         // Backward compatibility workaround.
    39         if (!is_string($engine)) {
    39         if (!is_string($engine)) {
    40             $params = array($engine, $params);
    40             $params = array($engine, $params);
    41             $engine = 'auto';
    41             $engine = 'auto';
    52         $class = 'Text_Diff_Engine_' . $engine;
    52         $class = 'Text_Diff_Engine_' . $engine;
    53         $diff_engine = new $class();
    53         $diff_engine = new $class();
    54 
    54 
    55         $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
    55         $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
    56     }
    56     }
       
    57 
       
    58 	/**
       
    59 	 * PHP4 constructor.
       
    60 	 */
       
    61 	public function Text_Diff( $engine, $params ) {
       
    62 		self::__construct( $engine, $params );
       
    63 	}
    57 
    64 
    58     /**
    65     /**
    59      * Returns the array of differences.
    66      * Returns the array of differences.
    60      */
    67      */
    61     function getDiff()
    68     function getDiff()
   302      *                                  $mapped_to_lines are what is actually
   309      *                                  $mapped_to_lines are what is actually
   303      *                                  compared when computing the diff.
   310      *                                  compared when computing the diff.
   304      * @param array $mapped_to_lines    This array should have the same number
   311      * @param array $mapped_to_lines    This array should have the same number
   305      *                                  of elements as $to_lines.
   312      *                                  of elements as $to_lines.
   306      */
   313      */
   307     function Text_MappedDiff($from_lines, $to_lines,
   314     function __construct($from_lines, $to_lines,
   308                              $mapped_from_lines, $mapped_to_lines)
   315                              $mapped_from_lines, $mapped_to_lines)
   309     {
   316     {
   310         assert(count($from_lines) == count($mapped_from_lines));
   317         assert(count($from_lines) == count($mapped_from_lines));
   311         assert(count($to_lines) == count($mapped_to_lines));
   318         assert(count($to_lines) == count($mapped_to_lines));
   312 
   319 
   326                 $yi += count($final);
   333                 $yi += count($final);
   327             }
   334             }
   328         }
   335         }
   329     }
   336     }
   330 
   337 
       
   338 	/**
       
   339 	 * PHP4 constructor.
       
   340 	 */
       
   341 	public function Text_MappedDiff( $from_lines, $to_lines,
       
   342                              $mapped_from_lines, $mapped_to_lines ) {
       
   343 		self::__construct( $from_lines, $to_lines,
       
   344                              $mapped_from_lines, $mapped_to_lines );
       
   345 	}
       
   346 
   331 }
   347 }
   332 
   348 
   333 /**
   349 /**
   334  * @package Text_Diff
   350  * @package Text_Diff
   335  * @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
   351  * @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
   364  *
   380  *
   365  * @access private
   381  * @access private
   366  */
   382  */
   367 class Text_Diff_Op_copy extends Text_Diff_Op {
   383 class Text_Diff_Op_copy extends Text_Diff_Op {
   368 
   384 
   369     function Text_Diff_Op_copy($orig, $final = false)
   385 	/**
       
   386 	 * PHP5 constructor.
       
   387 	 */
       
   388     function __construct( $orig, $final = false )
   370     {
   389     {
   371         if (!is_array($final)) {
   390         if (!is_array($final)) {
   372             $final = $orig;
   391             $final = $orig;
   373         }
   392         }
   374         $this->orig = $orig;
   393         $this->orig = $orig;
   375         $this->final = $final;
   394         $this->final = $final;
   376     }
   395     }
   377 
   396 
       
   397 	/**
       
   398 	 * PHP4 constructor.
       
   399 	 */
       
   400 	public function Text_Diff_Op_copy( $orig, $final = false ) {
       
   401 		self::__construct( $orig, $final );
       
   402 	}
       
   403 
   378     function &reverse()
   404     function &reverse()
   379     {
   405     {
   380         $reverse = new Text_Diff_Op_copy($this->final, $this->orig);
   406         $reverse = new Text_Diff_Op_copy($this->final, $this->orig);
   381         return $reverse;
   407         return $reverse;
   382     }
   408     }
   389  *
   415  *
   390  * @access private
   416  * @access private
   391  */
   417  */
   392 class Text_Diff_Op_delete extends Text_Diff_Op {
   418 class Text_Diff_Op_delete extends Text_Diff_Op {
   393 
   419 
   394     function Text_Diff_Op_delete($lines)
   420 	/**
       
   421 	 * PHP5 constructor.
       
   422 	 */
       
   423 	function __construct( $lines )
   395     {
   424     {
   396         $this->orig = $lines;
   425         $this->orig = $lines;
   397         $this->final = false;
   426         $this->final = false;
   398     }
   427     }
   399 
   428 
       
   429 	/**
       
   430 	 * PHP4 constructor.
       
   431 	 */
       
   432 	public function Text_Diff_Op_delete( $lines ) {
       
   433 		self::__construct( $lines );
       
   434 	}
       
   435 
   400     function &reverse()
   436     function &reverse()
   401     {
   437     {
   402         $reverse = new Text_Diff_Op_add($this->orig);
   438         $reverse = new Text_Diff_Op_add($this->orig);
   403         return $reverse;
   439         return $reverse;
   404     }
   440     }
   411  *
   447  *
   412  * @access private
   448  * @access private
   413  */
   449  */
   414 class Text_Diff_Op_add extends Text_Diff_Op {
   450 class Text_Diff_Op_add extends Text_Diff_Op {
   415 
   451 
   416     function Text_Diff_Op_add($lines)
   452 	/**
       
   453 	 * PHP5 constructor.
       
   454 	 */
       
   455     function __construct( $lines )
   417     {
   456     {
   418         $this->final = $lines;
   457         $this->final = $lines;
   419         $this->orig = false;
   458         $this->orig = false;
   420     }
   459     }
   421 
   460 
       
   461 	/**
       
   462 	 * PHP4 constructor.
       
   463 	 */
       
   464 	public function Text_Diff_Op_add( $lines ) {
       
   465 		self::__construct( $lines );
       
   466 	}
       
   467 
   422     function &reverse()
   468     function &reverse()
   423     {
   469     {
   424         $reverse = new Text_Diff_Op_delete($this->final);
   470         $reverse = new Text_Diff_Op_delete($this->final);
   425         return $reverse;
   471         return $reverse;
   426     }
   472     }
   433  *
   479  *
   434  * @access private
   480  * @access private
   435  */
   481  */
   436 class Text_Diff_Op_change extends Text_Diff_Op {
   482 class Text_Diff_Op_change extends Text_Diff_Op {
   437 
   483 
   438     function Text_Diff_Op_change($orig, $final)
   484 	/**
       
   485 	 * PHP5 constructor.
       
   486 	 */
       
   487     function __construct( $orig, $final )
   439     {
   488     {
   440         $this->orig = $orig;
   489         $this->orig = $orig;
   441         $this->final = $final;
   490         $this->final = $final;
   442     }
   491     }
   443 
   492 
       
   493 	/**
       
   494 	 * PHP4 constructor.
       
   495 	 */
       
   496 	public function Text_Diff_Op_change( $orig, $final ) {
       
   497 		self::__construct( $orig, $final );
       
   498 	}
       
   499 
   444     function &reverse()
   500     function &reverse()
   445     {
   501     {
   446         $reverse = new Text_Diff_Op_change($this->final, $this->orig);
   502         $reverse = new Text_Diff_Op_change($this->final, $this->orig);
   447         return $reverse;
   503         return $reverse;
   448     }
   504     }