Make WordPress Core


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

Update Text_Diff. Props simek. Fixes #9467

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/Text/Diff/Engine/string.php

    r7747 r13211  
    1111 * </code>
    1212 *
    13  * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $
    14  *
    1513 * Copyright 2005 Örjan Persson <o@42mm.org>
    16  * Copyright 2005-2008 The Horde Project (http://www.horde.org/)
     14 * Copyright 2005-2010 The Horde Project (http://www.horde.org/)
    1715 *
    1816 * See the enclosed file COPYING for license information (LGPL). If you did
     
    4038    function diff($diff, $mode = 'autodetect')
    4139    {
     40        // Detect line breaks.
     41        $lnbr = "\n";
     42        if (strpos($diff, "\r\n") !== false) {
     43            $lnbr = "\r\n";
     44        } elseif (strpos($diff, "\r") !== false) {
     45            $lnbr = "\r";
     46        }
     47
     48        // Make sure we have a line break at the EOF.
     49        if (substr($diff, -strlen($lnbr)) != $lnbr) {
     50            $diff .= $lnbr;
     51        }
     52
    4253        if ($mode != 'autodetect' && $mode != 'context' && $mode != 'unified') {
    4354            return PEAR::raiseError('Type of diff is unsupported');
     
    4960            if ($context === $unified) {
    5061                return PEAR::raiseError('Type of diff could not be detected');
    51             } elseif ($context === false || $context === false) {
     62            } elseif ($context === false || $unified === false) {
    5263                $mode = $context !== false ? 'context' : 'unified';
    5364            } else {
     
    5667        }
    5768
    58         // split by new line and remove the diff header
    59         $diff = explode("\n", $diff);
    60         array_shift($diff);
    61         array_shift($diff);
     69        // Split by new line and remove the diff header, if there is one.
     70        $diff = explode($lnbr, $diff);
     71        if (($mode == 'context' && strpos($diff[0], '***') === 0) ||
     72            ($mode == 'unified' && strpos($diff[0], '---') === 0)) {
     73            array_shift($diff);
     74            array_shift($diff);
     75        }
    6276
    6377        if ($mode == 'context') {
Note: See TracChangeset for help on using the changeset viewer.