public DiffFormatter::format(Diff $diff)
Format a diff.
Parameters
\Drupal\Component\Diff\Diff $diff: A Diff object.
Return value
string The formatted output.
File
- core/lib/Drupal/Component/Diff/DiffFormatter.php, line 48
Class
- DiffFormatter
- A class to format Diffs
Namespace
Drupal\Component\Diff
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | public function format(Diff $diff ) { $xi = $yi = 1; $block = FALSE; $context = array (); $nlead = $this ->leading_context_lines; $ntrail = $this ->trailing_context_lines; $this ->_start_diff(); foreach ( $diff ->getEdits() as $edit ) { if ( $edit ->type == 'copy' ) { if ( is_array ( $block )) { if (sizeof( $edit ->orig) <= $nlead + $ntrail ) { $block [] = $edit ; } else { if ( $ntrail ) { $context = array_slice ( $edit ->orig, 0, $ntrail ); $block [] = new DiffOpCopy( $context ); } $this ->_block( $x0 , $ntrail + $xi - $x0 , $y0 , $ntrail + $yi - $y0 , $block ); $block = FALSE; } } $context = $edit ->orig; } else { if (! is_array ( $block )) { $context = array_slice ( $context , sizeof( $context ) - $nlead ); $x0 = $xi - sizeof( $context ); $y0 = $yi - sizeof( $context ); $block = array (); if ( $context ) { $block [] = new DiffOpCopy( $context ); } } $block [] = $edit ; } if ( $edit ->orig) { $xi += sizeof( $edit ->orig); } if ( $edit ->closing) { $yi += sizeof( $edit ->closing); } } if ( is_array ( $block )) { $this ->_block( $x0 , $xi - $x0 , $y0 , $yi - $y0 , $block ); } $end = $this ->_end_diff(); if (! empty ( $xi )) { $this ->line_stats[ 'counter' ][ 'x' ] += $xi ; } if (! empty ( $yi )) { $this ->line_stats[ 'counter' ][ 'y' ] += $yi ; } return $end ; } |
Please login to continue.