36
36
* @author Chris Boulton <[email protected] >
37
37
* @copyright (c) 2009 Chris Boulton
38
38
* @license New BSD License http://www.opensource.org/licenses/bsd-license.php
39
- * @version 1.0
39
+ * @version 1.1
40
40
* @link http://github.com/chrisboulton/phpdiff
41
41
*/
42
42
@@ -58,13 +58,13 @@ class Diff_Renderer_Html_Array extends Diff_Renderer_Abstract
58
58
*
59
59
* @return array An array of the generated chances, suitable for presentation in HTML.
60
60
*/
61
- public function Render ()
61
+ public function render ()
62
62
{
63
63
// As we'll be modifying a & b to include our change markers,
64
64
// we need to get the contents and store them here. That way
65
65
// we're not going to destroy the original data
66
- $ a = $ this ->diff ->GetA ();
67
- $ b = $ this ->diff ->GetB ();
66
+ $ a = $ this ->diff ->getA ();
67
+ $ b = $ this ->diff ->getB ();
68
68
69
69
$ changes = array ();
70
70
$ opCodes = $ this ->diff ->getGroupedOpcodes ();
@@ -80,21 +80,20 @@ public function Render()
80
80
$ fromLine = $ a [$ i1 + $ i ];
81
81
$ toLine = $ b [$ j1 + $ i ];
82
82
83
- list ($ start , $ end ) = $ this ->GetChangeExtent ($ fromLine , $ toLine );
83
+ list ($ start , $ end ) = $ this ->getChangeExtent ($ fromLine , $ toLine );
84
84
if ($ start != 0 || $ end != 0 ) {
85
85
$ last = $ end + strlen ($ fromLine );
86
86
$ fromLine = substr_replace ($ fromLine , "\0" , $ start , 0 );
87
87
$ fromLine = substr_replace ($ fromLine , "\1" , $ last + 1 , 0 );
88
88
$ last = $ end + strlen ($ toLine );
89
89
$ toLine = substr_replace ($ toLine , "\0" , $ start , 0 );
90
90
$ toLine = substr_replace ($ toLine , "\1" , $ last + 1 , 0 );
91
- $ a [$ i1 ] = $ fromLine ;
92
- $ b [$ j1 ] = $ toLine ;
91
+ $ a [$ i1 + $ i ] = $ fromLine ;
92
+ $ b [$ j1 + $ i ] = $ toLine ;
93
93
}
94
94
}
95
95
}
96
96
97
-
98
97
if ($ tag != $ lastTag ) {
99
98
$ blocks [] = array (
100
99
'tag ' => $ tag ,
@@ -114,21 +113,21 @@ public function Render()
114
113
115
114
if ($ tag == 'equal ' ) {
116
115
$ lines = array_slice ($ a , $ i1 , ($ i2 - $ i1 ));
117
- $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ this ->FormatLines ($ lines );
116
+ $ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ this ->formatLines ($ lines );
118
117
$ lines = array_slice ($ b , $ j1 , ($ j2 - $ j1 ));
119
- $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ this ->FormatLines ($ lines );
118
+ $ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ this ->formatLines ($ lines );
120
119
}
121
120
else {
122
121
if ($ tag == 'replace ' || $ tag == 'delete ' ) {
123
122
$ lines = array_slice ($ a , $ i1 , ($ i2 - $ i1 ));
124
- $ lines = $ this ->FormatLines ($ lines );
123
+ $ lines = $ this ->formatLines ($ lines );
125
124
$ lines = str_replace (array ("\0" , "\1" ), array ('<del> ' , '</del> ' ), $ lines );
126
125
$ blocks [$ lastBlock ]['base ' ]['lines ' ] += $ lines ;
127
126
}
128
127
129
128
if ($ tag == 'replace ' || $ tag == 'insert ' ) {
130
129
$ lines = array_slice ($ b , $ j1 , ($ j2 - $ j1 ));
131
- $ lines = $ this ->FormatLines ($ lines );
130
+ $ lines = $ this ->formatLines ($ lines );
132
131
$ lines = str_replace (array ("\0" , "\1" ), array ('<ins> ' , '</ins> ' ), $ lines );
133
132
$ blocks [$ lastBlock ]['changed ' ]['lines ' ] += $ lines ;
134
133
}
@@ -173,12 +172,12 @@ private function GetChangeExtent($fromLine, $toLine)
173
172
* @param array $lines Array of lines to format.
174
173
* @return array Array of the formatted lines.
175
174
*/
176
- private function FormatLines ($ lines )
175
+ private function formatLines ($ lines )
177
176
{
178
177
$ lines = array_map (array ($ this , 'ExpandTabs ' ), $ lines );
179
178
$ lines = array_map (array ($ this , 'HtmlSafe ' ), $ lines );
180
179
foreach ($ lines as &$ line ) {
181
- $ line = preg_replace ('# ( +)|^ #e ' , "\$this->FixSpaces (' \\1') " , $ line );
180
+ $ line = preg_replace ('# ( +)|^ #e ' , "\$this->fixSpaces (' \\1') " , $ line );
182
181
}
183
182
return $ lines ;
184
183
}
@@ -189,7 +188,7 @@ private function FormatLines($lines)
189
188
* @param string $spaces The string of spaces.
190
189
* @return string The HTML representation of the string.
191
190
*/
192
- function FixSpaces ($ spaces ='' )
191
+ function fixSpaces ($ spaces ='' )
193
192
{
194
193
$ count = strlen ($ spaces );
195
194
if ($ count == 0 ) {
@@ -207,7 +206,7 @@ function FixSpaces($spaces='')
207
206
* @param string $line The containing tabs to convert.
208
207
* @return string The line with the tabs converted to spaces.
209
208
*/
210
- private function ExpandTabs ($ line )
209
+ private function expandTabs ($ line )
211
210
{
212
211
return str_replace ("\t" , str_repeat (' ' , $ this ->options ['tabSize ' ]), $ line );
213
212
}
@@ -218,7 +217,7 @@ private function ExpandTabs($line)
218
217
* @param string $string The string.
219
218
* @return string The string with the HTML characters replaced by entities.
220
219
*/
221
- private function HtmlSafe ($ string )
220
+ private function htmlSafe ($ string )
222
221
{
223
222
return htmlspecialchars ($ string , ENT_NOQUOTES , 'UTF-8 ' );
224
223
}
0 commit comments