Make WordPress Core


Ignore:
Timestamp:
02/19/2010 01:25:26 AM (17 years ago)
Author:
nacin
Message:

Update Text_Diff. Props simek. Fixes #9467

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/Text/Diff/Renderer/inline.php

    r8581 r13211  
    33 * "Inline" diff renderer.
    44 *
    5  * $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.21 2008/01/04 10:07:51 jan Exp $
    6  *
    7  * Copyright 2004-2008 The Horde Project (http://www.horde.org/)
     5 * Copyright 2004-2010 The Horde Project (http://www.horde.org/)
    86 *
    97 * See the enclosed file COPYING for license information (LGPL). If you did
    … …  
    3129    /**
    3230     * Number of leading context "lines" to preserve.
     31     *
     32     * @var integer
    3333     */
    3434    var $_leading_context_lines = 10000;
    … …  
    3636    /**
    3737     * Number of trailing context "lines" to preserve.
     38     *
     39     * @var integer
    3840     */
    3941    var $_trailing_context_lines = 10000;
    … …  
    4143    /**
    4244     * Prefix for inserted text.
     45     *
     46     * @var string
    4347     */
    4448    var $_ins_prefix = '<ins>';
    … …  
    4650    /**
    4751     * Suffix for inserted text.
     52     *
     53     * @var string
    4854     */
    4955    var $_ins_suffix = '</ins>';
    … …  
    5157    /**
    5258     * Prefix for deleted text.
     59     *
     60     * @var string
    5361     */
    5462    var $_del_prefix = '<del>';
    … …  
    5664    /**
    5765     * Suffix for deleted text.
     66     *
     67     * @var string
    5868     */
    5969    var $_del_suffix = '</del>';
    … …  
    6171    /**
    6272     * Header for each change block.
     73     *
     74     * @var string
    6375     */
    6476    var $_block_header = '';
    6577
    6678    /**
     79     * Whether to split down to character-level.
     80     *
     81     * @var boolean
     82     */
     83    var $_split_characters = false;
     84
     85    /**
    6786     * What are we currently splitting on? Used to recurse to show word-level
    68      * changes.
     87     * or character-level changes.
     88     *
     89     * @var string
    6990     */
    7091    var $_split_level = 'lines';
    … …  
    86107        }
    87108
    88         if ($this->_split_level == 'words') {
     109        if ($this->_split_level == 'lines') {
     110            return implode("\n", $lines) . "\n";
     111        } else {
    89112            return implode('', $lines);
    90         } else {
    91             return implode("\n", $lines) . "\n";
    92113        }
    93114    }
    … …  
    111132    function _changed($orig, $final)
    112133    {
    113         /* If we've already split on words, don't try to do so again - just
    114          * display. */
     134        /* If we've already split on characters, just display. */
     135        if ($this->_split_level == 'characters') {
     136            return $this->_deleted($orig)
     137                . $this->_added($final);
     138        }
     139
     140        /* If we've already split on words, just display. */
    115141        if ($this->_split_level == 'words') {
    116142            $prefix = '';
    … …  
    131157        $nl = "\0";
    132158
    133         /* We want to split on word boundaries, but we need to
    134          * preserve whitespace as well. Therefore we split on words,
    135          * but include all blocks of whitespace in the wordlist. */
    136         $diff = new Text_Diff($this->_splitOnWords($text1, $nl),
    137                               $this->_splitOnWords($text2, $nl));
     159        if ($this->_split_characters) {
     160            $diff = new Text_Diff('native',
     161                                  array(preg_split('//', $text1),
     162                                        preg_split('//', $text2)));
     163        } else {
     164            /* We want to split on word boundaries, but we need to preserve
     165             * whitespace as well. Therefore we split on words, but include
     166             * all blocks of whitespace in the wordlist. */
     167            $diff = new Text_Diff('native',
     168                                  array($this->_splitOnWords($text1, $nl),
     169                                        $this->_splitOnWords($text2, $nl)));
     170        }
    138171
    139172        /* Get the diff in inline format. */
    140         $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(),
    141                                                               array('split_level' => 'words')));
     173        $renderer = new Text_Diff_Renderer_inline
     174            (array_merge($this->getParams(),
     175                         array('split_level' => $this->_split_characters ? 'characters' : 'words')));
    142176
    143177        /* Run the diff and get the output. */
Note: See TracChangeset for help on using the changeset viewer.