Changeset 13211
- Timestamp:
- 02/19/2010 01:25:26 AM (15 years ago)
- Location:
- trunk/wp-includes/Text
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/Text/Diff.php
r8581 r13211 7 7 * <dairiki@dairiki.org>, and is used/adapted with his permission. 8 8 * 9 * $Horde: framework/Text_Diff/Diff.php,v 1.26 2008/01/04 10:07:49 jan Exp $10 *11 9 * Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org> 12 * Copyright 2004-20 08The Horde Project (http://www.horde.org/)10 * Copyright 2004-2010 The Horde Project (http://www.horde.org/) 13 11 * 14 12 * See the enclosed file COPYING for license information (LGPL). If you did … … 64 62 { 65 63 return $this->_edits; 64 } 65 66 /** 67 * returns the number of new (added) lines in a given diff. 68 * 69 * @since Text_Diff 1.1.0 70 * 71 * @return integer The number of new lines 72 */ 73 function countAddedLines() 74 { 75 $count = 0; 76 foreach ($this->_edits as $edit) { 77 if (is_a($edit, 'Text_Diff_Op_add') || 78 is_a($edit, 'Text_Diff_Op_change')) { 79 $count += $edit->nfinal(); 80 } 81 } 82 return $count; 83 } 84 85 /** 86 * Returns the number of deleted (removed) lines in a given diff. 87 * 88 * @since Text_Diff 1.1.0 89 * 90 * @return integer The number of deleted lines 91 */ 92 function countDeletedLines() 93 { 94 $count = 0; 95 foreach ($this->_edits as $edit) { 96 if (is_a($edit, 'Text_Diff_Op_delete') || 97 is_a($edit, 'Text_Diff_Op_change')) { 98 $count += $edit->norig(); 99 } 100 } 101 return $count; 66 102 } 67 103 -
trunk/wp-includes/Text/Diff/Engine/native.php
r7747 r13211 1 1 <?php 2 2 /** 3 * $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.10 2008/01/04 10:27:53 jan Exp $ 4 * 5 * Class used internally by Text_Diff to actually compute the diffs. This 6 * class is implemented using native PHP code. 3 * Class used internally by Text_Diff to actually compute the diffs. 4 * 5 * This class is implemented using native PHP code. 7 6 * 8 7 * The algorithm used here is mostly lifted from the perl module … … 20 19 * code was written by him, and is used/adapted with his permission. 21 20 * 22 * Copyright 2004-20 08The Horde Project (http://www.horde.org/)21 * Copyright 2004-2010 The Horde Project (http://www.horde.org/) 23 22 * 24 23 * See the enclosed file COPYING for license information (LGPL). If you did -
trunk/wp-includes/Text/Diff/Engine/shell.php
r7747 r13211 6 6 * differences between the two input arrays. 7 7 * 8 * $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.8 2008/01/04 10:07:50 jan Exp $ 9 * 10 * Copyright 2007-2008 The Horde Project (http://www.horde.org/) 8 * Copyright 2007-2010 The Horde Project (http://www.horde.org/) 11 9 * 12 10 * See the enclosed file COPYING for license information (LGPL). If you did -
trunk/wp-includes/Text/Diff/Engine/string.php
r7747 r13211 11 11 * </code> 12 12 * 13 * $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.7 2008/01/04 10:07:50 jan Exp $14 *15 13 * Copyright 2005 Örjan Persson <o@42mm.org> 16 * Copyright 2005-20 08The Horde Project (http://www.horde.org/)14 * Copyright 2005-2010 The Horde Project (http://www.horde.org/) 17 15 * 18 16 * See the enclosed file COPYING for license information (LGPL). If you did … … 40 38 function diff($diff, $mode = 'autodetect') 41 39 { 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 42 53 if ($mode != 'autodetect' && $mode != 'context' && $mode != 'unified') { 43 54 return PEAR::raiseError('Type of diff is unsupported'); … … 49 60 if ($context === $unified) { 50 61 return PEAR::raiseError('Type of diff could not be detected'); 51 } elseif ($context === false || $ context=== false) {62 } elseif ($context === false || $unified === false) { 52 63 $mode = $context !== false ? 'context' : 'unified'; 53 64 } else { … … 56 67 } 57 68 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 } 62 76 63 77 if ($mode == 'context') { -
trunk/wp-includes/Text/Diff/Engine/xdiff.php
r7747 r13211 6 6 * to compute the differences between the two input arrays. 7 7 * 8 * $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.6 2008/01/04 10:07:50 jan Exp $ 9 * 10 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 8 * Copyright 2004-2010 The Horde Project (http://www.horde.org/) 11 9 * 12 10 * See the enclosed file COPYING for license information (LGPL). If you did … … 43 41 $edits = array(); 44 42 foreach ($diff as $line) { 43 if (!strlen($line)) { 44 continue; 45 } 45 46 switch ($line[0]) { 46 47 case ' ': -
trunk/wp-includes/Text/Diff/Renderer.php
r7747 r13211 6 6 * this class be customized via inheritance, to obtain fancier outputs. 7 7 * 8 * $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.21 2008/01/04 10:07:50 jan Exp $ 9 * 10 * Copyright 2004-2008 The Horde Project (http://www.horde.org/) 8 * Copyright 2004-2010 The Horde Project (http://www.horde.org/) 11 9 * 12 10 * See the enclosed file COPYING for license information (LGPL). If you did -
trunk/wp-includes/Text/Diff/Renderer/inline.php
r8581 r13211 3 3 * "Inline" diff renderer. 4 4 * 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/) 8 6 * 9 7 * See the enclosed file COPYING for license information (LGPL). If you did … … 31 29 /** 32 30 * Number of leading context "lines" to preserve. 31 * 32 * @var integer 33 33 */ 34 34 var $_leading_context_lines = 10000; … … 36 36 /** 37 37 * Number of trailing context "lines" to preserve. 38 * 39 * @var integer 38 40 */ 39 41 var $_trailing_context_lines = 10000; … … 41 43 /** 42 44 * Prefix for inserted text. 45 * 46 * @var string 43 47 */ 44 48 var $_ins_prefix = '<ins>'; … … 46 50 /** 47 51 * Suffix for inserted text. 52 * 53 * @var string 48 54 */ 49 55 var $_ins_suffix = '</ins>'; … … 51 57 /** 52 58 * Prefix for deleted text. 59 * 60 * @var string 53 61 */ 54 62 var $_del_prefix = '<del>'; … … 56 64 /** 57 65 * Suffix for deleted text. 66 * 67 * @var string 58 68 */ 59 69 var $_del_suffix = '</del>'; … … 61 71 /** 62 72 * Header for each change block. 73 * 74 * @var string 63 75 */ 64 76 var $_block_header = ''; 65 77 66 78 /** 79 * Whether to split down to character-level. 80 * 81 * @var boolean 82 */ 83 var $_split_characters = false; 84 85 /** 67 86 * What are we currently splitting on? Used to recurse to show word-level 68 * changes. 87 * or character-level changes. 88 * 89 * @var string 69 90 */ 70 91 var $_split_level = 'lines'; … … 86 107 } 87 108 88 if ($this->_split_level == 'words') { 109 if ($this->_split_level == 'lines') { 110 return implode("\n", $lines) . "\n"; 111 } else { 89 112 return implode('', $lines); 90 } else {91 return implode("\n", $lines) . "\n";92 113 } 93 114 } … … 111 132 function _changed($orig, $final) 112 133 { 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. */ 115 141 if ($this->_split_level == 'words') { 116 142 $prefix = ''; … … 131 157 $nl = "\0"; 132 158 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 } 138 171 139 172 /* 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'))); 142 176 143 177 /* Run the diff and get the output. */
Note: See TracChangeset
for help on using the changeset viewer.