diff -r 2f6f6f7551ca -r 32102edaa81b web/wp-includes/Text/Diff/Renderer/inline.php --- a/web/wp-includes/Text/Diff/Renderer/inline.php Thu Sep 16 15:45:36 2010 +0000 +++ b/web/wp-includes/Text/Diff/Renderer/inline.php Mon Nov 19 18:26:13 2012 +0100 @@ -2,9 +2,7 @@ /** * "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. @@ -30,42 +28,65 @@ /** * 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 = ''; /** * Suffix for inserted text. + * + * @var string */ var $_ins_suffix = ''; /** * Prefix for deleted text. + * + * @var string */ var $_del_prefix = ''; /** * Suffix for deleted text. + * + * @var string */ var $_del_suffix = ''; /** * 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'; @@ -85,10 +106,10 @@ array_walk($lines, array(&$this, '_encode')); } - if ($this->_split_level == 'words') { + if ($this->_split_level == 'lines') { + return implode("\n", $lines) . "\n"; + } else { return implode('', $lines); - } else { - return implode("\n", $lines) . "\n"; } } @@ -110,8 +131,13 @@ 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 && @@ -130,15 +156,23 @@ /* 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";