ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WordLevelDiff Class Reference
+ Inheritance diagram for WordLevelDiff:
+ Collaboration diagram for WordLevelDiff:

Public Member Functions

 __construct ($orig_lines, $closing_lines)
 Constructor. More...
 
 _split ($lines)
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
- Public Member Functions inherited from MappedDiff
 __construct ( $from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 Constructor. More...
 
- Public Member Functions inherited from Diff
 __construct ($from_lines, $to_lines)
 Constructor. More...
 
 reverse ()
 Compute reversed Diff. More...
 
 isEmpty ()
 Check for empty diff. More...
 
 lcs ()
 Compute the length of the Longest Common Subsequence (LCS). More...
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
 _check ($from_lines, $to_lines)
 Check a Diff for validity. More...
 

Data Fields

const MAX_LINE_LENGTH = 10000
 
- Data Fields inherited from Diff
 $edits
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

WordLevelDiff::__construct (   $from_lines,
  $to_lines 
)

Constructor.

Computes diff between sequences of strings.

Parameters
$from_linesarray An array of strings. (Typically these are lines from a file.)
$to_linesarray An array of strings.

Reimplemented from Diff.

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

1107 {
1108 $fname = 'WordLevelDiff::WordLevelDiff';
1109 //wfProfileIn( $fname );
1110
1111 list($orig_words, $orig_stripped) = $this->_split($orig_lines);
1112 list($closing_words, $closing_stripped) = $this->_split($closing_lines);
1113
1115 $orig_words,
1116 $closing_words,
1117 $orig_stripped,
1118 $closing_stripped
1119 );
1120 //wfProfileOut( $fname );
1121 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and _split().

+ Here is the call graph for this function:

Member Function Documentation

◆ _split()

WordLevelDiff::_split (   $lines)

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

1124 {
1125 $fname = 'WordLevelDiff::_split';
1126 //wfProfileIn( $fname );
1127
1128 $words = array();
1129 $stripped = array();
1130 $first = true;
1131 foreach ($lines as $line) {
1132 # If the line is too long, just pretend the entire line is one big word
1133 # This prevents resource exhaustion problems
1134 if ($first) {
1135 $first = false;
1136 } else {
1137 $words[] = "\n";
1138 $stripped[] = "\n";
1139 }
1140 if (strlen($line) > self::MAX_LINE_LENGTH) {
1141 $words[] = $line;
1142 $stripped[] = $line;
1143 } else {
1144 $m = array();
1145 if (preg_match_all(
1146 '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
1147 $line,
1148 $m
1149 )) {
1150 $words = array_merge($words, $m[0]);
1151 $stripped = array_merge($stripped, $m[1]);
1152 }
1153 }
1154 }
1155 //wfProfileOut( $fname );
1156 return array($words, $stripped);
1157 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ closing()

WordLevelDiff::closing ( )

Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns
array The sequence of strings.

Reimplemented from Diff.

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

1178 {
1179 $fname = 'WordLevelDiff::closing';
1180 //wfProfileIn( $fname );
1181 $closing = new _HWLDF_WordAccumulator();
1182
1183 foreach ($this->edits as $edit) {
1184 if ($edit->type == 'copy') {
1185 $closing->addWords($edit->closing);
1186 } elseif ($edit->closing) {
1187 $closing->addWords($edit->closing, 'ins');
1188 }
1189 }
1190 $lines = $closing->getLines();
1191 //wfProfileOut( $fname );
1192 return $lines;
1193 }

◆ orig()

WordLevelDiff::orig ( )

Get the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns
array The original sequence of strings.

Reimplemented from Diff.

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

1160 {
1161 $fname = 'WordLevelDiff::orig';
1162 //wfProfileIn( $fname );
1163 $orig = new _HWLDF_WordAccumulator();
1164
1165 foreach ($this->edits as $edit) {
1166 if ($edit->type == 'copy') {
1167 $orig->addWords($edit->orig);
1168 } elseif ($edit->orig) {
1169 $orig->addWords($edit->orig, 'del');
1170 }
1171 }
1172 $lines = $orig->getLines();
1173 //wfProfileOut( $fname );
1174 return $lines;
1175 }

Field Documentation

◆ MAX_LINE_LENGTH

const WordLevelDiff::MAX_LINE_LENGTH = 10000

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


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