ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
DiffFormatter Class Reference
+ Collaboration diagram for DiffFormatter:

Public Member Functions

 format ($diff)
 Format a diff. More...
 
 _block ($xbeg, $xlen, $ybeg, $ylen, $edits)
 
 _start_diff ()
 
 _end_diff ()
 
 _block_header ($xbeg, $xlen, $ybeg, $ylen)
 
 _start_block ($header)
 
 _end_block ()
 
 _lines ($lines, $prefix=' ')
 
 _context ($lines)
 
 _added ($lines)
 
 _deleted ($lines)
 
 _changed ($orig, $closing)
 

Data Fields

 $leading_context_lines = 0
 Number of leading context "lines" to preserve. More...
 
 $trailing_context_lines = 0
 Number of trailing context "lines" to preserve. More...
 

Detailed Description

Definition at line 831 of file class.WordLevelDiff.php.

Member Function Documentation

◆ _added()

DiffFormatter::_added (   $lines)

Definition at line 993 of file class.WordLevelDiff.php.

994 {
995 $this->_lines($lines, '>');
996 }
_lines($lines, $prefix=' ')

References _lines().

Referenced by _block(), and _changed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _block()

DiffFormatter::_block (   $xbeg,
  $xlen,
  $ybeg,
  $ylen,
  $edits 
)

Definition at line 926 of file class.WordLevelDiff.php.

927 {
928 $fname = 'DiffFormatter::_block';
929 //wfProfileIn( $fname );
930 $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen));
931 foreach ($edits as $edit) {
932 if ($edit->type == 'copy') {
933 $this->_context($edit->orig);
934 } elseif ($edit->type == 'add') {
935 $this->_added($edit->closing);
936 } elseif ($edit->type == 'delete') {
937 $this->_deleted($edit->orig);
938 } elseif ($edit->type == 'change') {
939 $this->_changed($edit->orig, $edit->closing);
940 } else {
941 throw new \RuntimeException('Unknown edit type');
942 }
943 }
944 $this->_end_block();
945 //wfProfileOut( $fname );
946 }
_block_header($xbeg, $xlen, $ybeg, $ylen)
_changed($orig, $closing)

References _added(), _block_header(), _changed(), _context(), _deleted(), _end_block(), and _start_block().

Referenced by format().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _block_header()

DiffFormatter::_block_header (   $xbeg,
  $xlen,
  $ybeg,
  $ylen 
)

Definition at line 960 of file class.WordLevelDiff.php.

961 {
962 if ($xlen > 1) {
963 $xbeg .= "," . ($xbeg + $xlen - 1);
964 }
965 if ($ylen > 1) {
966 $ybeg .= "," . ($ybeg + $ylen - 1);
967 }
968
969 return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
970 }

Referenced by _block().

+ Here is the caller graph for this function:

◆ _changed()

DiffFormatter::_changed (   $orig,
  $closing 
)

Definition at line 1002 of file class.WordLevelDiff.php.

1003 {
1004 $this->_deleted($orig);
1005 echo "---\n";
1006 $this->_added($closing);
1007 }

References _added(), and _deleted().

Referenced by _block().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _context()

DiffFormatter::_context (   $lines)

Definition at line 988 of file class.WordLevelDiff.php.

989 {
990 $this->_lines($lines);
991 }

References _lines().

Referenced by _block().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _deleted()

DiffFormatter::_deleted (   $lines)

Definition at line 997 of file class.WordLevelDiff.php.

998 {
999 $this->_lines($lines, '<');
1000 }

References _lines().

Referenced by _block(), and _changed().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _end_block()

DiffFormatter::_end_block ( )

Definition at line 977 of file class.WordLevelDiff.php.

978 {
979 }

Referenced by _block().

+ Here is the caller graph for this function:

◆ _end_diff()

DiffFormatter::_end_diff ( )

Definition at line 953 of file class.WordLevelDiff.php.

954 {
955 $val = ob_get_contents();
956 ob_end_clean();
957 return $val;
958 }

Referenced by format().

+ Here is the caller graph for this function:

◆ _lines()

DiffFormatter::_lines (   $lines,
  $prefix = ' ' 
)

Definition at line 981 of file class.WordLevelDiff.php.

982 {
983 foreach ($lines as $line) {
984 echo "$prefix $line\n";
985 }
986 }

Referenced by _added(), _context(), and _deleted().

+ Here is the caller graph for this function:

◆ _start_block()

DiffFormatter::_start_block (   $header)

Definition at line 972 of file class.WordLevelDiff.php.

973 {
974 echo $header;
975 }

Referenced by _block().

+ Here is the caller graph for this function:

◆ _start_diff()

DiffFormatter::_start_diff ( )

Definition at line 948 of file class.WordLevelDiff.php.

949 {
950 ob_start();
951 }

Referenced by format().

+ Here is the caller graph for this function:

◆ format()

DiffFormatter::format (   $diff)

Format a diff.

Parameters
$diffobject A Diff object.
Returns
string The formatted output.

Definition at line 855 of file class.WordLevelDiff.php.

856 {
857 $fname = 'DiffFormatter::format';
858 //wfProfileIn( $fname );
859
860 $xi = $yi = 1;
861 $block = false;
862 $context = array();
863
866
867 $this->_start_diff();
868
869 foreach ($diff->edits as $edit) {
870 if ($edit->type == 'copy') {
871 if (is_array($block)) {
872 if (sizeof($edit->orig) <= $nlead + $ntrail) {
873 $block[] = $edit;
874 } else {
875 if ($ntrail) {
876 $context = array_slice($edit->orig, 0, $ntrail);
877 $block[] = new _DiffOp_Copy($context);
878 }
879 $this->_block(
880 $x0,
881 $ntrail + $xi - $x0,
882 $y0,
883 $ntrail + $yi - $y0,
884 $block
885 );
886 $block = false;
887 }
888 }
889 $context = $edit->orig;
890 } else {
891 if (!is_array($block)) {
892 $context = array_slice($context, sizeof($context) - $nlead);
893 $x0 = $xi - sizeof($context);
894 $y0 = $yi - sizeof($context);
895 $block = array();
896 if ($context) {
897 $block[] = new _DiffOp_Copy($context);
898 }
899 }
900 $block[] = $edit;
901 }
902
903 if ($edit->orig) {
904 $xi += sizeof($edit->orig);
905 }
906 if ($edit->closing) {
907 $yi += sizeof($edit->closing);
908 }
909 }
910
911 if (is_array($block)) {
912 $this->_block(
913 $x0,
914 $xi - $x0,
915 $y0,
916 $yi - $y0,
917 $block
918 );
919 }
920
921 $end = $this->_end_diff();
922 //wfProfileOut( $fname );
923 return $end;
924 }
_block($xbeg, $xlen, $ybeg, $ylen, $edits)
$leading_context_lines
Number of leading context "lines" to preserve.
$trailing_context_lines
Number of trailing context "lines" to preserve.
$context
Definition: webdav.php:31

References $context, $leading_context_lines, $trailing_context_lines, _block(), _end_diff(), and _start_diff().

+ Here is the call graph for this function:

Field Documentation

◆ $leading_context_lines

DiffFormatter::$leading_context_lines = 0

Number of leading context "lines" to preserve.

This should be left at zero for this class, but subclasses may want to set this to other values.

Definition at line 839 of file class.WordLevelDiff.php.

Referenced by format().

◆ $trailing_context_lines

DiffFormatter::$trailing_context_lines = 0

Number of trailing context "lines" to preserve.

This should be left at zero for this class, but subclasses may want to set this to other values.

Definition at line 847 of file class.WordLevelDiff.php.

Referenced by format().


The documentation for this class was generated from the following file: