]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/Text/Diff.php
WordPress 4.6.2
[autoinstalls/wordpress.git] / wp-includes / Text / Diff.php
index 06d1c6c76407da8f0253136c47d1bd858bce1eea..edcdd3ac3a0d27dde7b2560d30a621d6f7b6c4cf 100644 (file)
@@ -6,10 +6,8 @@
  * The original PHP version of this code was written by Geoffrey T. Dairiki
  * <dairiki@dairiki.org>, and is used/adapted with his permission.
  *
- * $Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $
- *
  * Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org>
- * Copyright 2004-2008 The Horde Project (http://www.horde.org/)
+ * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
  *
  * See the enclosed file COPYING for license information (LGPL). If you did
  * not receive this file, see http://opensource.org/licenses/lgpl-license.php.
@@ -35,7 +33,7 @@ class Text_Diff {
      *                           Normally an array of two arrays, each
      *                           containing the lines from a file.
      */
-    function Text_Diff($engine, $params)
+    function __construct( $engine, $params )
     {
         // Backward compatibility workaround.
         if (!is_string($engine)) {
@@ -57,6 +55,13 @@ class Text_Diff {
         $this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_Diff( $engine, $params ) {
+               self::__construct( $engine, $params );
+       }
+
     /**
      * Returns the array of differences.
      */
@@ -65,6 +70,44 @@ class Text_Diff {
         return $this->_edits;
     }
 
+    /**
+     * returns the number of new (added) lines in a given diff.
+     *
+     * @since Text_Diff 1.1.0
+     *
+     * @return integer The number of new lines
+     */
+    function countAddedLines()
+    {
+        $count = 0;
+        foreach ($this->_edits as $edit) {
+            if (is_a($edit, 'Text_Diff_Op_add') ||
+                is_a($edit, 'Text_Diff_Op_change')) {
+                $count += $edit->nfinal();
+            }
+        }
+        return $count;
+    }
+
+    /**
+     * Returns the number of deleted (removed) lines in a given diff.
+     *
+     * @since Text_Diff 1.1.0
+     *
+     * @return integer The number of deleted lines
+     */
+    function countDeletedLines()
+    {
+        $count = 0;
+        foreach ($this->_edits as $edit) {
+            if (is_a($edit, 'Text_Diff_Op_delete') ||
+                is_a($edit, 'Text_Diff_Op_change')) {
+                $count += $edit->norig();
+            }
+        }
+        return $count;
+    }
+
     /**
      * Computes a reversed diff.
      *
@@ -169,7 +212,7 @@ class Text_Diff {
      * @param string $line  The line to trim.
      * @param integer $key  The index of the line in the array. Not used.
      */
-    function trimNewlines(&$line, $key)
+    static function trimNewlines(&$line, $key)
     {
         $line = str_replace(array("\n", "\r"), '', $line);
     }
@@ -268,7 +311,7 @@ class Text_MappedDiff extends Text_Diff {
      * @param array $mapped_to_lines    This array should have the same number
      *                                  of elements as $to_lines.
      */
-    function Text_MappedDiff($from_lines, $to_lines,
+    function __construct($from_lines, $to_lines,
                              $mapped_from_lines, $mapped_to_lines)
     {
         assert(count($from_lines) == count($mapped_from_lines));
@@ -292,6 +335,15 @@ class Text_MappedDiff extends Text_Diff {
         }
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_MappedDiff( $from_lines, $to_lines,
+                             $mapped_from_lines, $mapped_to_lines ) {
+               self::__construct( $from_lines, $to_lines,
+                             $mapped_from_lines, $mapped_to_lines );
+       }
+
 }
 
 /**
@@ -330,7 +382,10 @@ class Text_Diff_Op {
  */
 class Text_Diff_Op_copy extends Text_Diff_Op {
 
-    function Text_Diff_Op_copy($orig, $final = false)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $orig, $final = false )
     {
         if (!is_array($final)) {
             $final = $orig;
@@ -339,9 +394,16 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
         $this->final = $final;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_Diff_Op_copy( $orig, $final = false ) {
+               self::__construct( $orig, $final );
+       }
+
     function &reverse()
     {
-        $reverse = &new Text_Diff_Op_copy($this->final, $this->orig);
+        $reverse = new Text_Diff_Op_copy($this->final, $this->orig);
         return $reverse;
     }
 
@@ -355,15 +417,25 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
  */
 class Text_Diff_Op_delete extends Text_Diff_Op {
 
-    function Text_Diff_Op_delete($lines)
+       /**
+        * PHP5 constructor.
+        */
+       function __construct( $lines )
     {
         $this->orig = $lines;
         $this->final = false;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_Diff_Op_delete( $lines ) {
+               self::__construct( $lines );
+       }
+
     function &reverse()
     {
-        $reverse = &new Text_Diff_Op_add($this->orig);
+        $reverse = new Text_Diff_Op_add($this->orig);
         return $reverse;
     }
 
@@ -377,15 +449,25 @@ class Text_Diff_Op_delete extends Text_Diff_Op {
  */
 class Text_Diff_Op_add extends Text_Diff_Op {
 
-    function Text_Diff_Op_add($lines)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $lines )
     {
         $this->final = $lines;
         $this->orig = false;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_Diff_Op_add( $lines ) {
+               self::__construct( $lines );
+       }
+
     function &reverse()
     {
-        $reverse = &new Text_Diff_Op_delete($this->final);
+        $reverse = new Text_Diff_Op_delete($this->final);
         return $reverse;
     }
 
@@ -399,15 +481,25 @@ class Text_Diff_Op_add extends Text_Diff_Op {
  */
 class Text_Diff_Op_change extends Text_Diff_Op {
 
-    function Text_Diff_Op_change($orig, $final)
+       /**
+        * PHP5 constructor.
+        */
+    function __construct( $orig, $final )
     {
         $this->orig = $orig;
         $this->final = $final;
     }
 
+       /**
+        * PHP4 constructor.
+        */
+       public function Text_Diff_Op_change( $orig, $final ) {
+               self::__construct( $orig, $final );
+       }
+
     function &reverse()
     {
-        $reverse = &new Text_Diff_Op_change($this->final, $this->orig);
+        $reverse = new Text_Diff_Op_change($this->final, $this->orig);
         return $reverse;
     }