Blame Identity/Webenv/App/phpBB/3.0.4/includes/diff/diff.php

f2e824
f2e824
/**
f2e824
*
f2e824
* @package diff
f2e824
* @version $Id: diff.php 8765 2008-08-16 22:18:25Z aptx $
f2e824
* @copyright (c) 2006 phpBB Group
f2e824
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
f2e824
*
f2e824
*/
f2e824
f2e824
/**
f2e824
* @ignore
f2e824
*/
f2e824
if (!defined('IN_PHPBB'))
f2e824
{
f2e824
	exit;
f2e824
}
f2e824
f2e824
/**
f2e824
* Code from pear.php.net, Text_Diff-1.0.0 package
f2e824
* http://pear.php.net/package/Text_Diff/
f2e824
*
f2e824
* Modified by phpBB Group to meet our coding standards
f2e824
* and being able to integrate into phpBB
f2e824
*
f2e824
* General API for generating and formatting diffs - the differences between
f2e824
* two sequences of strings.
f2e824
*
f2e824
* Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
* Copyright 2004-2008 The Horde Project (http://www.horde.org/)
f2e824
*
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*/
f2e824
class diff
f2e824
{
f2e824
	/**
f2e824
	* Array of changes.
f2e824
	* @var array
f2e824
	*/
f2e824
	var $_edits;
f2e824
f2e824
	/**
f2e824
	* Computes diffs between sequences of strings.
f2e824
	*
f2e824
	* @param array $from_lines  An array of strings. Typically these are lines from a file.
f2e824
	* @param array $to_lines    An array of strings.
f2e824
	*/
f2e824
	function diff(&$from_content, &$to_content, $preserve_cr = true)
f2e824
	{
f2e824
		$diff_engine = new diff_engine();
f2e824
		$this->_edits = $diff_engine->diff($from_content, $to_content, $preserve_cr);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Returns the array of differences.
f2e824
	*/
f2e824
	function get_diff()
f2e824
	{
f2e824
		return $this->_edits;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Computes a reversed diff.
f2e824
	*
f2e824
	* Example:
f2e824
	* 
f2e824
	* $diff = new diff($lines1, $lines2);
f2e824
	* $rev = $diff->reverse();
f2e824
	* 
f2e824
	*
f2e824
	* @return diff  A Diff object representing the inverse of the original diff.
f2e824
	*               Note that we purposely don't return a reference here, since
f2e824
	*               this essentially is a clone() method.
f2e824
	*/
f2e824
	function reverse()
f2e824
	{
f2e824
		if (version_compare(zend_version(), '2', '>'))
f2e824
		{
f2e824
			$rev = clone($this);
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$rev = $this;
f2e824
		}
f2e824
f2e824
		$rev->_edits = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			$rev->_edits[] = $edit->reverse();
f2e824
		}
f2e824
f2e824
		return $rev;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Checks for an empty diff.
f2e824
	*
f2e824
	* @return boolean  True if two sequences were identical.
f2e824
	*/
f2e824
	function is_empty()
f2e824
	{
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if (!is_a($edit, 'diff_op_copy'))
f2e824
			{
f2e824
				return false;
f2e824
			}
f2e824
		}
f2e824
		return true;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Computes the length of the Longest Common Subsequence (LCS).
f2e824
	*
f2e824
	* This is mostly for diagnostic purposes.
f2e824
	*
f2e824
	* @return integer  The length of the LCS.
f2e824
	*/
f2e824
	function lcs()
f2e824
	{
f2e824
		$lcs = 0;
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if (is_a($edit, 'diff_op_copy'))
f2e824
			{
f2e824
				$lcs += sizeof($edit->orig);
f2e824
			}
f2e824
		}
f2e824
		return $lcs;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Gets the original set of lines.
f2e824
	*
f2e824
	* This reconstructs the $from_lines parameter passed to the constructor.
f2e824
	*
f2e824
	* @return array  The original sequence of strings.
f2e824
	*/
f2e824
	function get_original()
f2e824
	{
f2e824
		$lines = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->orig)
f2e824
			{
f2e824
				array_splice($lines, sizeof($lines), 0, $edit->orig);
f2e824
			}
f2e824
		}
f2e824
		return $lines;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Gets the final set of lines.
f2e824
	*
f2e824
	* This reconstructs the $to_lines parameter passed to the constructor.
f2e824
	*
f2e824
	* @return array  The sequence of strings.
f2e824
	*/
f2e824
	function get_final()
f2e824
	{
f2e824
		$lines = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->final)
f2e824
			{
f2e824
				array_splice($lines, sizeof($lines), 0, $edit->final);
f2e824
			}
f2e824
		}
f2e824
		return $lines;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Removes trailing newlines from a line of text. This is meant to be used with array_walk().
f2e824
	*
f2e824
	* @param string &$line  The line to trim.
f2e824
	* @param integer $key  The index of the line in the array. Not used.
f2e824
	*/
f2e824
	function trim_newlines(&$line, $key)
f2e824
	{
f2e824
		$line = str_replace(array("\n", "\r"), '', $line);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Checks a diff for validity.
f2e824
	*
f2e824
	* This is here only for debugging purposes.
f2e824
	*/
f2e824
	function _check($from_lines, $to_lines)
f2e824
	{
f2e824
		if (serialize($from_lines) != serialize($this->get_original()))
f2e824
		{
f2e824
			trigger_error("[diff] Reconstructed original doesn't match", E_USER_ERROR);
f2e824
		}
f2e824
f2e824
		if (serialize($to_lines) != serialize($this->get_final()))
f2e824
		{
f2e824
			trigger_error("[diff] Reconstructed final doesn't match", E_USER_ERROR);
f2e824
		}
f2e824
f2e824
		$rev = $this->reverse();
f2e824
f2e824
		if (serialize($to_lines) != serialize($rev->get_original()))
f2e824
		{
f2e824
			trigger_error("[diff] Reversed original doesn't match", E_USER_ERROR);
f2e824
		}
f2e824
f2e824
		if (serialize($from_lines) != serialize($rev->get_final()))
f2e824
		{
f2e824
			trigger_error("[diff] Reversed final doesn't match", E_USER_ERROR);
f2e824
		}
f2e824
f2e824
		$prevtype = null;
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($prevtype == get_class($edit))
f2e824
			{
f2e824
				trigger_error("[diff] Edit sequence is non-optimal", E_USER_ERROR);
f2e824
			}
f2e824
			$prevtype = get_class($edit);
f2e824
		}
f2e824
f2e824
		return true;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*/
f2e824
class mapped_diff extends diff
f2e824
{
f2e824
	/**
f2e824
	* Computes a diff between sequences of strings.
f2e824
	*
f2e824
	* This can be used to compute things like case-insensitve diffs, or diffs
f2e824
	* which ignore changes in white-space.
f2e824
	*
f2e824
	* @param array $from_lines         An array of strings.
f2e824
	* @param array $to_lines           An array of strings.
f2e824
	* @param array $mapped_from_lines  This array should have the same size number of elements as $from_lines.
f2e824
	*                                  The elements in $mapped_from_lines and $mapped_to_lines are what is actually
f2e824
	*                                  compared when computing the diff.
f2e824
	* @param array $mapped_to_lines    This array should have the same number of elements as $to_lines.
f2e824
	*/
f2e824
	function mapped_diff(&$from_lines, &$to_lines, &$mapped_from_lines, &$mapped_to_lines)
f2e824
	{
f2e824
		if (sizeof($from_lines) != sizeof($mapped_from_lines) || sizeof($to_lines) != sizeof($mapped_to_lines))
f2e824
		{
f2e824
			return false;
f2e824
		}
f2e824
f2e824
		parent::diff($mapped_from_lines, $mapped_to_lines);
f2e824
f2e824
		$xi = $yi = 0;
f2e824
		for ($i = 0; $i < sizeof($this->_edits); $i++)
f2e824
		{
f2e824
			$orig = &$this->_edits[$i]->orig;
f2e824
			if (is_array($orig))
f2e824
			{
f2e824
				$orig = array_slice($from_lines, $xi, sizeof($orig));
f2e824
				$xi += sizeof($orig);
f2e824
			}
f2e824
f2e824
			$final = &$this->_edits[$i]->final;
f2e824
			if (is_array($final))
f2e824
			{
f2e824
				$final = array_slice($to_lines, $yi, sizeof($final));
f2e824
				$yi += sizeof($final);
f2e824
			}
f2e824
		}
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff_op
f2e824
{
f2e824
	var $orig;
f2e824
	var $final;
f2e824
f2e824
	function &reverse()
f2e824
	{
f2e824
		trigger_error('[diff] Abstract method', E_USER_ERROR);
f2e824
	}
f2e824
f2e824
	function norig()
f2e824
	{
f2e824
		return ($this->orig) ? sizeof($this->orig) : 0;
f2e824
	}
f2e824
f2e824
	function nfinal()
f2e824
	{
f2e824
		return ($this->final) ? sizeof($this->final) : 0;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff_op_copy extends diff_op
f2e824
{
f2e824
	function diff_op_copy($orig, $final = false)
f2e824
	{
f2e824
		if (!is_array($final))
f2e824
		{
f2e824
			$final = $orig;
f2e824
		}
f2e824
		$this->orig = $orig;
f2e824
		$this->final = $final;
f2e824
	}
f2e824
f2e824
	function &reverse()
f2e824
	{
f2e824
		$reverse = new diff_op_copy($this->final, $this->orig);
f2e824
		return $reverse;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff_op_delete extends diff_op
f2e824
{
f2e824
	function diff_op_delete($lines)
f2e824
	{
f2e824
		$this->orig = $lines;
f2e824
		$this->final = false;
f2e824
	}
f2e824
f2e824
	function &reverse()
f2e824
	{
f2e824
		$reverse = new diff_op_add($this->orig);
f2e824
		return $reverse;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff_op_add extends diff_op
f2e824
{
f2e824
	function diff_op_add($lines)
f2e824
	{
f2e824
		$this->final = $lines;
f2e824
		$this->orig = false;
f2e824
	}
f2e824
f2e824
	function &reverse()
f2e824
	{
f2e824
		$reverse = new diff_op_delete($this->final);
f2e824
		return $reverse;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff_op_change extends diff_op
f2e824
{
f2e824
	function diff_op_change($orig, $final)
f2e824
	{
f2e824
		$this->orig = $orig;
f2e824
		$this->final = $final;
f2e824
	}
f2e824
f2e824
	function &reverse()
f2e824
	{
f2e824
		$reverse = new diff_op_change($this->final, $this->orig);
f2e824
		return $reverse;
f2e824
	}
f2e824
}
f2e824
f2e824
f2e824
/**
f2e824
* A class for computing three way diffs.
f2e824
*
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*/
f2e824
class diff3 extends diff
f2e824
{
f2e824
	/**
f2e824
	* Conflict counter.
f2e824
	* @var integer
f2e824
	*/
f2e824
	var $_conflicting_blocks = 0;
f2e824
f2e824
	/**
f2e824
	* Computes diff between 3 sequences of strings.
f2e824
	*
f2e824
	* @param array $orig    The original lines to use.
f2e824
	* @param array $final1  The first version to compare to.
f2e824
	* @param array $final2  The second version to compare to.
f2e824
	*/
f2e824
	function diff3(&$orig, &$final1, &$final2)
f2e824
	{
f2e824
		$diff_engine = new diff_engine();
f2e824
f2e824
		$diff_1 = $diff_engine->diff($orig, $final1);
f2e824
		$diff_2 = $diff_engine->diff($orig, $final2);
f2e824
f2e824
		unset($engine);
f2e824
f2e824
		$this->_edits = $this->_diff3($diff_1, $diff_2);
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Return merged output
f2e824
	*
f2e824
	* @param string $label1 the cvs file version/label from the original set of lines
f2e824
	* @param string $label2 the cvs file version/label from the new set of lines
f2e824
	* @param string $label_sep the explanation between label1 and label2 - more of a helper for the user
f2e824
	* @param bool $get_conflicts if set to true only the number of conflicts is returned
f2e824
	* @param bool $merge_new if set to true the merged output will have the new file contents on a conflicting merge
f2e824
	*
f2e824
	* @return mixed the merged output
f2e824
	*/
f2e824
	function merged_output($label1 = 'CURRENT_FILE', $label2 = 'NEW_FILE', $label_sep = 'DIFF_SEP_EXPLAIN', $get_conflicts = false, $merge_new = false)
f2e824
	{
f2e824
		global $user;
f2e824
f2e824
		if ($get_conflicts)
f2e824
		{
f2e824
			foreach ($this->_edits as $edit)
f2e824
			{
f2e824
				if ($edit->is_conflict())
f2e824
				{
f2e824
					$this->_conflicting_blocks++;
f2e824
				}
f2e824
			}
f2e824
f2e824
			return $this->_conflicting_blocks;
f2e824
		}
f2e824
f2e824
		$label1 = (!empty($user->lang[$label1])) ? $user->lang[$label1] : $label1;
f2e824
		$label2 = (!empty($user->lang[$label2])) ? $user->lang[$label2] : $label2;
f2e824
		$label_sep = (!empty($user->lang[$label_sep])) ? $user->lang[$label_sep] : $label_sep;
f2e824
f2e824
		$lines = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->is_conflict())
f2e824
			{
f2e824
				if (!$merge_new)
f2e824
				{
f2e824
					$lines = array_merge($lines, array('<<<<<<<' . ($label1 ? ' ' . $label1 : '')), $edit->final1, array('=======' . ($label_sep ? ' ' . $label_sep : '')), $edit->final2, array('>>>>>>>' . ($label2 ? ' ' . $label2 : '')));
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					$lines = array_merge($lines, $edit->final1);
f2e824
				}
f2e824
				$this->_conflicting_blocks++;
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$lines = array_merge($lines, $edit->merged());
f2e824
			}
f2e824
		}
f2e824
f2e824
		return $lines;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Merge the output and use the new file code for conflicts
f2e824
	*/
f2e824
	function merged_new_output()
f2e824
	{
f2e824
		$lines = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->is_conflict())
f2e824
			{
f2e824
				$lines = array_merge($lines, $edit->final2);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$lines = array_merge($lines, $edit->merged());
f2e824
			}
f2e824
		}
f2e824
f2e824
		return $lines;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Merge the output and use the original file code for conflicts
f2e824
	*/
f2e824
	function merged_orig_output()
f2e824
	{
f2e824
		$lines = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->is_conflict())
f2e824
			{
f2e824
				$lines = array_merge($lines, $edit->final1);
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$lines = array_merge($lines, $edit->merged());
f2e824
			}
f2e824
		}
f2e824
f2e824
		return $lines;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* Get conflicting block(s)
f2e824
	*/
f2e824
	function get_conflicts()
f2e824
	{
f2e824
		$conflicts = array();
f2e824
f2e824
		foreach ($this->_edits as $edit)
f2e824
		{
f2e824
			if ($edit->is_conflict())
f2e824
			{
f2e824
				$conflicts[] = array($edit->final1, $edit->final2);
f2e824
			}
f2e824
		}
f2e824
f2e824
		return $conflicts;
f2e824
	}
f2e824
f2e824
	/**
f2e824
	* @access private
f2e824
	*/
f2e824
	function _diff3(&$edits1, &$edits2)
f2e824
	{
f2e824
		$edits = array();
f2e824
		$bb = new diff3_block_builder();
f2e824
f2e824
		$e1 = current($edits1);
f2e824
		$e2 = current($edits2);
f2e824
f2e824
		while ($e1 || $e2)
f2e824
		{
f2e824
			if ($e1 && $e2 && is_a($e1, 'diff_op_copy') && is_a($e2, 'diff_op_copy'))
f2e824
			{
f2e824
				// We have copy blocks from both diffs. This is the (only) time we want to emit a diff3 copy block.
f2e824
				// Flush current diff3 diff block, if any.
f2e824
				if ($edit = $bb->finish())
f2e824
				{
f2e824
					$edits[] = $edit;
f2e824
				}
f2e824
f2e824
				$ncopy = min($e1->norig(), $e2->norig());
f2e824
				$edits[] = new diff3_op_copy(array_slice($e1->orig, 0, $ncopy));
f2e824
f2e824
				if ($e1->norig() > $ncopy)
f2e824
				{
f2e824
					array_splice($e1->orig, 0, $ncopy);
f2e824
					array_splice($e1->final, 0, $ncopy);
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					$e1 = next($edits1);
f2e824
				}
f2e824
f2e824
				if ($e2->norig() > $ncopy)
f2e824
				{
f2e824
					array_splice($e2->orig, 0, $ncopy);
f2e824
					array_splice($e2->final, 0, $ncopy);
f2e824
				}
f2e824
				else
f2e824
				{
f2e824
					$e2 = next($edits2);
f2e824
				}
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				if ($e1 && $e2)
f2e824
				{
f2e824
					if ($e1->orig && $e2->orig)
f2e824
					{
f2e824
						$norig = min($e1->norig(), $e2->norig());
f2e824
						$orig = array_splice($e1->orig, 0, $norig);
f2e824
						array_splice($e2->orig, 0, $norig);
f2e824
						$bb->input($orig);
f2e824
					}
f2e824
					else
f2e824
					{
f2e824
						$norig = 0;
f2e824
					}
f2e824
f2e824
					if (is_a($e1, 'diff_op_copy'))
f2e824
					{
f2e824
						$bb->out1(array_splice($e1->final, 0, $norig));
f2e824
					}
f2e824
f2e824
					if (is_a($e2, 'diff_op_copy'))
f2e824
					{
f2e824
						$bb->out2(array_splice($e2->final, 0, $norig));
f2e824
					}
f2e824
				}
f2e824
f2e824
				if ($e1 && ! $e1->orig)
f2e824
				{
f2e824
					$bb->out1($e1->final);
f2e824
					$e1 = next($edits1);
f2e824
				}
f2e824
f2e824
				if ($e2 && ! $e2->orig)
f2e824
				{
f2e824
					$bb->out2($e2->final);
f2e824
					$e2 = next($edits2);
f2e824
				}
f2e824
			}
f2e824
		}
f2e824
f2e824
		if ($edit = $bb->finish())
f2e824
		{
f2e824
			$edits[] = $edit;
f2e824
		}
f2e824
f2e824
		return $edits;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff3_op
f2e824
{
f2e824
	function diff3_op($orig = false, $final1 = false, $final2 = false)
f2e824
	{
f2e824
		$this->orig = $orig ? $orig : array();
f2e824
		$this->final1 = $final1 ? $final1 : array();
f2e824
		$this->final2 = $final2 ? $final2 : array();
f2e824
	}
f2e824
f2e824
	function merged()
f2e824
	{
f2e824
		if (!isset($this->_merged))
f2e824
		{
f2e824
			if ($this->final1 === $this->final2)
f2e824
			{
f2e824
				$this->_merged = &$this->final1;
f2e824
			}
f2e824
			else if ($this->final1 === $this->orig)
f2e824
			{
f2e824
				$this->_merged = &$this->final2;
f2e824
			}
f2e824
			else if ($this->final2 === $this->orig)
f2e824
			{
f2e824
				$this->_merged = &$this->final1;
f2e824
			}
f2e824
			else
f2e824
			{
f2e824
				$this->_merged = false;
f2e824
			}
f2e824
		}
f2e824
f2e824
		return $this->_merged;
f2e824
	}
f2e824
f2e824
	function is_conflict()
f2e824
	{
f2e824
		return ($this->merged() === false) ? true : false;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff3_op_copy extends diff3_op
f2e824
{
f2e824
	function diff3_op_copy($lines = false)
f2e824
	{
f2e824
		$this->orig = $lines ? $lines : array();
f2e824
		$this->final1 = &$this->orig;
f2e824
		$this->final2 = &$this->orig;
f2e824
	}
f2e824
f2e824
	function merged()
f2e824
	{
f2e824
		return $this->orig;
f2e824
	}
f2e824
f2e824
	function is_conflict()
f2e824
	{
f2e824
		return false;
f2e824
	}
f2e824
}
f2e824
f2e824
/**
f2e824
* @package diff
f2e824
* @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
f2e824
*
f2e824
* @access private
f2e824
*/
f2e824
class diff3_block_builder
f2e824
{
f2e824
	function diff3_block_builder()
f2e824
	{
f2e824
		$this->_init();
f2e824
	}
f2e824
f2e824
	function input($lines)
f2e824
	{
f2e824
		if ($lines)
f2e824
		{
f2e824
			$this->_append($this->orig, $lines);
f2e824
		}
f2e824
	}
f2e824
f2e824
	function out1($lines)
f2e824
	{
f2e824
		if ($lines)
f2e824
		{
f2e824
			$this->_append($this->final1, $lines);
f2e824
		}
f2e824
	}
f2e824
f2e824
	function out2($lines)
f2e824
	{
f2e824
		if ($lines)
f2e824
		{
f2e824
			$this->_append($this->final2, $lines);
f2e824
		}
f2e824
	}
f2e824
f2e824
	function is_empty()
f2e824
	{
f2e824
		return !$this->orig && !$this->final1 && !$this->final2;
f2e824
	}
f2e824
f2e824
	function finish()
f2e824
	{
f2e824
		if ($this->is_empty())
f2e824
		{
f2e824
			return false;
f2e824
		}
f2e824
		else
f2e824
		{
f2e824
			$edit = new diff3_op($this->orig, $this->final1, $this->final2);
f2e824
			$this->_init();
f2e824
			return $edit;
f2e824
		}
f2e824
	}
f2e824
f2e824
	function _init()
f2e824
	{
f2e824
		$this->orig = $this->final1 = $this->final2 = array();
f2e824
	}
f2e824
f2e824
	function _append(&$array, $lines)
f2e824
	{
f2e824
		array_splice($array, sizeof($array), 0, $lines);
f2e824
	}
f2e824
}
f2e824
f2e824
?>