3737 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3838 * POSSIBILITY OF SUCH DAMAGE.
3939 *
40- * @package DiffLib
40+ * @package jblond\Diff\Renderer\Html
4141 * @author Chris Boulton <[email protected] > 4242 * @copyright (c) 2009 Chris Boulton
4343 * @license New BSD License http://www.opensource.org/licenses/bsd-license.php
44- * @version 1.9
44+ * @version 1.10
4545 * @link https://github.com/JBlond/php-diff
4646 */
47-
48- /**
49- * Class Diff_Renderer_Html_Array
50- */
5147class HtmlArray extends RendererAbstract
5248{
5349 /**
@@ -59,62 +55,6 @@ class HtmlArray extends RendererAbstract
5955 'title_b ' => 'New Version ' ,
6056 );
6157
62- /**
63- * From https://gist.github.com/stemar/8287074
64- * @param string $string The input string.
65- * @param string $replacement The replacement string.
66- * @param int $start If start is positive, the replacing will begin at the start'th offset into string.
67- * If start is negative, the replacing will begin at the start'th character from the end of string.
68- * @param int|null $length If given and is positive, it represents the length of the portion of string which is to
69- * be replaced. If it is negative, it represents the number of characters from the end of string at which to
70- * stop replacing. If it is not given, then it will default to strlen( string ); i.e. end the replacing at the
71- * end of string. Of course, if length is zero then this function will have the effect of inserting replacement
72- * into string at the given start offset.
73- * @return string|array The result string is returned. If string is an array then array is returned.
74- */
75- public function mbSubstrReplace (string $ string , string $ replacement , int $ start , $ length = null )
76- {
77- if (is_array ($ string )) {
78- $ num = count ($ string );
79- // $replacement
80- if (is_array ($ replacement )) {
81- $ replacement = array_slice ($ replacement , 0 , $ num );
82- } else {
83- $ replacement = array_pad (array ($ replacement ), $ num , $ replacement );
84- }
85-
86- // $start
87- if (is_array ($ start )) {
88- $ start = array_slice ($ start , 0 , $ num );
89- foreach ($ start as $ key => $ value ) {
90- $ start [$ key ] = is_int ($ value ) ? $ value : 0 ;
91- }
92- } else {
93- $ start = array_pad (array ($ start ), $ num , $ start );
94- }
95- // $length
96- if (!isset ($ length )) {
97- $ length = array_fill (0 , $ num , 0 );
98- } elseif (is_array ($ length )) {
99- $ length = array_slice ($ length , 0 , $ num );
100- foreach ($ length as $ key => $ value ) {
101- $ length [$ key ] = isset ($ value ) ? (is_int ($ value ) ? $ value : $ num ) : 0 ;
102- }
103- } else {
104- $ length = array_pad (array ($ length ), $ num , $ length );
105- }
106- // Recursive call
107- return array_map (array ($ this , 'mbSubstrReplace ' ), $ string , $ replacement , $ start , $ length );
108- }
109- preg_match_all ('/./us ' , (string )$ string , $ smatches );
110- preg_match_all ('/./us ' , (string )$ replacement , $ rmatches );
111- if ($ length === null ) {
112- $ length = mb_strlen ($ string );
113- }
114- array_splice ($ smatches ['0 ' ], $ start , $ length , $ rmatches [0 ]);
115- return join ($ smatches ['0 ' ]);
116- }
117-
11858 /**
11959 * @param string|array $changes
12060 * @param SideBySide|Inline $object
@@ -175,8 +115,8 @@ public function render()
175115 // As we'll be modifying a & b to include our change markers,
176116 // we need to get the contents and store them here. That way
177117 // we're not going to destroy the original data
178- $ a = $ this ->diff ->getA ();
179- $ b = $ this ->diff ->getB ();
118+ $ a = $ this ->diff ->getOld ();
119+ $ b = $ this ->diff ->getNew ();
180120
181121 $ changes = array ();
182122 $ opCodes = $ this ->diff ->getGroupedOpcodes ();
@@ -281,9 +221,19 @@ private function getChangeExtent(string $fromLine, string $toLine)
281221 protected function formatLines (array $ lines ) : array
282222 {
283223 if ($ this ->options ['tabSize ' ] !== false ) {
284- $ lines = array_map (array ($ this , 'ExpandTabs ' ), $ lines );
224+ $ lines = array_map (
225+ function ($ item ) {
226+ return $ this ->expandTabs ($ item );
227+ },
228+ $ lines
229+ );
285230 }
286- $ lines = array_map (array ($ this , 'HtmlSafe ' ), $ lines );
231+ $ lines = array_map (
232+ function ($ item ) {
233+ return $ this ->htmlSafe ($ item );
234+ },
235+ $ lines
236+ );
287237 foreach ($ lines as &$ line ) {
288238 $ line = preg_replace_callback ('# ( +)|^ # ' , array ($ this , 'fixSpaces ' ), $ line );
289239 }
0 commit comments