/**
* "Inline" diff renderer.
*
- * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.21 2008/01/04 10:07:51 jan Exp $
- *
- * 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.
/**
* Number of leading context "lines" to preserve.
+ *
+ * @var integer
*/
var $_leading_context_lines = 10000;
/**
* Number of trailing context "lines" to preserve.
+ *
+ * @var integer
*/
var $_trailing_context_lines = 10000;
/**
* Prefix for inserted text.
+ *
+ * @var string
*/
var $_ins_prefix = '<ins>';
/**
* Suffix for inserted text.
+ *
+ * @var string
*/
var $_ins_suffix = '</ins>';
/**
* Prefix for deleted text.
+ *
+ * @var string
*/
var $_del_prefix = '<del>';
/**
* Suffix for deleted text.
+ *
+ * @var string
*/
var $_del_suffix = '</del>';
/**
* Header for each change block.
+ *
+ * @var string
*/
var $_block_header = '';
+ /**
+ * Whether to split down to character-level.
+ *
+ * @var boolean
+ */
+ var $_split_characters = false;
+
/**
* What are we currently splitting on? Used to recurse to show word-level
- * changes.
+ * or character-level changes.
+ *
+ * @var string
*/
var $_split_level = 'lines';
array_walk($lines, array(&$this, '_encode'));
}
- if ($this->_split_level == 'words') {
- return implode('', $lines);
- } else {
+ if ($this->_split_level == 'lines') {
return implode("\n", $lines) . "\n";
+ } else {
+ return implode('', $lines);
}
}
function _changed($orig, $final)
{
- /* If we've already split on words, don't try to do so again - just
- * display. */
+ /* If we've already split on characters, just display. */
+ if ($this->_split_level == 'characters') {
+ return $this->_deleted($orig)
+ . $this->_added($final);
+ }
+
+ /* If we've already split on words, just display. */
if ($this->_split_level == 'words') {
$prefix = '';
while ($orig[0] !== false && $final[0] !== false &&
/* Non-printing newline marker. */
$nl = "\0";
- /* We want to split on word boundaries, but we need to
- * preserve whitespace as well. Therefore we split on words,
- * but include all blocks of whitespace in the wordlist. */
- $diff = new Text_Diff($this->_splitOnWords($text1, $nl),
- $this->_splitOnWords($text2, $nl));
+ if ($this->_split_characters) {
+ $diff = new Text_Diff('native',
+ array(preg_split('//', $text1),
+ preg_split('//', $text2)));
+ } else {
+ /* We want to split on word boundaries, but we need to preserve
+ * whitespace as well. Therefore we split on words, but include
+ * all blocks of whitespace in the wordlist. */
+ $diff = new Text_Diff('native',
+ array($this->_splitOnWords($text1, $nl),
+ $this->_splitOnWords($text2, $nl)));
+ }
/* Get the diff in inline format. */
- $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(),
- array('split_level' => 'words')));
+ $renderer = new Text_Diff_Renderer_inline
+ (array_merge($this->getParams(),
+ array('split_level' => $this->_split_characters ? 'characters' : 'words')));
/* Run the diff and get the output. */
return str_replace($nl, "\n", $renderer->render($diff)) . "\n";