Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/diff/engine.php

    r400 r702  
    33*
    44* @package diff
    5 * @version $Id: engine.php 8765 2008-08-16 22:18:25Z aptx $
     5* @version $Id$
    66* @copyright (c) 2006 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    1818
    1919/**
    20 * Code from pear.php.net, Text_Diff-1.0.0 package
     20* Code from pear.php.net, Text_Diff-1.1.0 package
    2121* http://pear.php.net/package/Text_Diff/ (native engine)
    2222*
     
    5050class diff_engine
    5151{
     52        /**
     53        * If set to true we trim all lines before we compare them. This ensures that sole space/tab changes do not trigger diffs.
     54        */
     55        var $skip_whitespace_changes = true;
     56
    5257        function diff(&$from_lines, &$to_lines, $preserve_cr = true)
    5358        {
     
    8691                for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++)
    8792                {
    88                         if ($from_lines[$skip] !== $to_lines[$skip])
     93                        if (trim($from_lines[$skip]) !== trim($to_lines[$skip]))
    8994                        {
    9095                                break;
     
    99104                for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++)
    100105                {
    101                         if ($from_lines[$xi] !== $to_lines[$yi])
     106                        if (trim($from_lines[$xi]) !== trim($to_lines[$yi]))
    102107                        {
    103108                                break;
     
    109114                for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
    110115                {
    111                         $xhash[$from_lines[$xi]] = 1;
     116                        if ($this->skip_whitespace_changes) $xhash[trim($from_lines[$xi])] = 1; else $xhash[$from_lines[$xi]] = 1;
    112117                }
    113118
    114119                for ($yi = $skip; $yi < $n_to - $endskip; $yi++)
    115120                {
    116                         $line = $to_lines[$yi];
     121                        $line = ($this->skip_whitespace_changes) ? trim($to_lines[$yi]) : $to_lines[$yi];
    117122
    118123                        if (($this->ychanged[$yi] = empty($xhash[$line])))
     
    127132                for ($xi = $skip; $xi < $n_from - $endskip; $xi++)
    128133                {
    129                         $line = $from_lines[$xi];
     134                        $line = ($this->skip_whitespace_changes) ? trim($from_lines[$xi]) : $from_lines[$xi];
    130135
    131136                        if (($this->xchanged[$xi] = empty($yhash[$line])))
     
    141146
    142147                // Merge edits when possible.
    143                 $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
    144                 $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
     148                if ($this->skip_whitespace_changes)
     149                {
     150                        $from_lines_clean = array_map('trim', $from_lines);
     151                        $to_lines_clean = array_map('trim', $to_lines);
     152
     153                        $this->_shift_boundaries($from_lines_clean, $this->xchanged, $this->ychanged);
     154                        $this->_shift_boundaries($to_lines_clean, $this->ychanged, $this->xchanged);
     155
     156                        unset($from_lines_clean, $to_lines_clean);
     157                }
     158                else
     159                {
     160                        $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged);
     161                        $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged);
     162                }
    145163
    146164                // Compute the edit operations.
Note: See TracChangeset for help on using the changeset viewer.