class WordLevelDiff in Diff 6
Same name and namespace in other branches
- 5.2 DiffEngine.php \WordLevelDiff
- 5 DiffEngine.php \WordLevelDiff
- 6.2 DiffEngine.php \WordLevelDiff
- 7.3 DiffEngine.php \WordLevelDiff
- 7.2 DiffEngine.php \WordLevelDiff
@todo document @private @subpackage DifferenceEngine
Hierarchy
- class \Diff
- class \MappedDiff
- class \WordLevelDiff
- class \MappedDiff
Expanded class hierarchy of WordLevelDiff
File
- ./
DiffEngine.php, line 961
View source
class WordLevelDiff extends MappedDiff {
function MAX_LINE_LENGTH() {
return 10000;
}
function WordLevelDiff($orig_lines, $closing_lines) {
list($orig_words, $orig_stripped) = $this
->_split($orig_lines);
list($closing_words, $closing_stripped) = $this
->_split($closing_lines);
$this
->MappedDiff($orig_words, $closing_words, $orig_stripped, $closing_stripped);
}
function _split($lines) {
$words = array();
$stripped = array();
$first = true;
foreach ($lines as $line) {
# If the line is too long, just pretend the entire line is one big word
# This prevents resource exhaustion problems
if ($first) {
$first = false;
}
else {
$words[] = "\n";
$stripped[] = "\n";
}
if (strlen($line) > $this
->MAX_LINE_LENGTH()) {
$words[] = $line;
$stripped[] = $line;
}
else {
if (preg_match_all('/ ( [^\\S\\n]+ | [0-9_A-Za-z\\x80-\\xff]+ | . ) (?: (?!< \\n) [^\\S\\n])? /xs', $line, $m)) {
$words = array_merge($words, $m[0]);
$stripped = array_merge($stripped, $m[1]);
}
}
}
return array(
$words,
$stripped,
);
}
function orig() {
$orig = new _HWLDF_WordAccumulator();
foreach ($this->edits as $edit) {
if ($edit->type == 'copy') {
$orig
->addWords($edit->orig);
}
elseif ($edit->orig) {
$orig
->addWords($edit->orig, 'mark');
}
}
$lines = $orig
->getLines();
return $lines;
}
function closing() {
$closing = new _HWLDF_WordAccumulator();
foreach ($this->edits as $edit) {
if ($edit->type == 'copy') {
$closing
->addWords($edit->closing);
}
elseif ($edit->closing) {
$closing
->addWords($edit->closing, 'mark');
}
}
$lines = $closing
->getLines();
return $lines;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Diff:: |
property | |||
Diff:: |
function | * Constructor. * Computes diff between sequences of strings. * * | ||
Diff:: |
function | * Check for empty diff. * * | ||
Diff:: |
function | * Compute the length of the Longest Common Subsequence (LCS). * * This is mostly for diagnostic purposed. * * | ||
Diff:: |
function | * Compute reversed Diff. * * SYNOPSIS: * * $diff = new Diff($lines1, $lines2); * $rev = $diff->reverse(); * | ||
Diff:: |
function | * Check a Diff for validity. * * This is here only for debugging purposes. | ||
MappedDiff:: |
function | * Constructor. * * Computes diff between sequences of strings. * * This can be used to compute things like * case-insensitve diffs, or diffs which ignore * changes in white-space. * * | ||
WordLevelDiff:: |
function |
* Get the closing set of lines.
*
* This reconstructs the $to_lines parameter passed to the
* constructor.
*
* Overrides Diff:: |
||
WordLevelDiff:: |
function | |||
WordLevelDiff:: |
function |
* Get the original set of lines.
*
* This reconstructs the $from_lines parameter passed to the
* constructor.
*
* Overrides Diff:: |
||
WordLevelDiff:: |
function | |||
WordLevelDiff:: |
function |