Text_Diff_Engine_string::parseUnifiedDiff() public WP 1.0
Parses an array containing the unified diff.
{} It's a method of the class: Text_Diff_Engine_string{}
No Hooks.
Return
Array. List of all diff operations.
Usage
$Text_Diff_Engine_string = new Text_Diff_Engine_string(); $Text_Diff_Engine_string->parseUnifiedDiff( $diff );
- $diff(array) (required)
- Array of lines.
Code of Text_Diff_Engine_string::parseUnifiedDiff() Text Diff Engine string::parseUnifiedDiff WP 5.6
function parseUnifiedDiff($diff)
{
$edits = array();
$end = count($diff) - 1;
for ($i = 0; $i < $end;) {
$diff1 = array();
switch (substr($diff[$i], 0, 1)) {
case ' ':
do {
$diff1[] = substr($diff[$i], 1);
} while (++$i < $end && substr($diff[$i], 0, 1) == ' ');
$edits[] = new Text_Diff_Op_copy($diff1);
break;
case '+':
// get all new lines
do {
$diff1[] = substr($diff[$i], 1);
} while (++$i < $end && substr($diff[$i], 0, 1) == '+');
$edits[] = new Text_Diff_Op_add($diff1);
break;
case '-':
// get changed or removed lines
$diff2 = array();
do {
$diff1[] = substr($diff[$i], 1);
} while (++$i < $end && substr($diff[$i], 0, 1) == '-');
while ($i < $end && substr($diff[$i], 0, 1) == '+') {
$diff2[] = substr($diff[$i++], 1);
}
if (count($diff2) == 0) {
$edits[] = new Text_Diff_Op_delete($diff1);
} else {
$edits[] = new Text_Diff_Op_change($diff1, $diff2);
}
break;
default:
$i++;
break;
}
}
return $edits;
}