15use UnexpectedValueException;
64 foreach ( $diff->edits as $edit ) {
65 if ( $edit->type ==
'copy' ) {
66 if ( is_array( $block ) ) {
67 if ( count( $edit->orig ) <= $nlead + $ntrail ) {
71 $context = array_slice( $edit->orig, 0, $ntrail );
74 $this->
block( $x0, $ntrail + $xi - $x0,
75 $y0, $ntrail + $yi - $y0,
80 $context = $edit->orig;
82 if ( !is_array( $block ) ) {
83 $context = array_slice( $context, count( $context ) - $nlead );
84 $x0 = $xi - count( $context );
85 $y0 = $yi - count( $context );
95 $xi += count( $edit->orig );
97 if ( $edit->closing ) {
98 $yi += count( $edit->closing );
102 if ( is_array( $block ) ) {
103 $this->
block( $x0, $xi - $x0,
120 protected function block( $xbeg, $xlen, $ybeg, $ylen, &$edits ) {
122 foreach ( $edits as $edit ) {
123 if ( $edit->type ==
'copy' ) {
125 } elseif ( $edit->type ==
'add' ) {
126 $this->
added( $edit->closing );
127 } elseif ( $edit->type ==
'delete' ) {
129 } elseif ( $edit->type ==
'change' ) {
130 $this->
changed( $edit->orig, $edit->closing );
132 throw new UnexpectedValueException(
"Unknown edit type: {$edit->type}" );
148 $this->result .= $text;
155 $val = $this->result;
171 $xbeg .=
',' . ( $xbeg + $xlen - 1 );
174 $ybeg .=
',' . ( $ybeg + $ylen - 1 );
177 return $xbeg . ( $xlen ? ( $ylen ?
'c' :
'd' ) :
'a' ) . $ybeg;
203 protected function lines( $lines, $prefix =
' ' ) {
204 foreach ( $lines as $line ) {
213 $this->
lines( $lines );
219 protected function added( $lines ) {
220 $this->
lines( $lines,
'>' );
227 $this->
lines( $lines,
'<' );
236 protected function changed( $orig, $closing ) {
239 $this->
added( $closing );
245class_alias( DiffFormatter::class,
'DiffFormatter' );