1.20.x diff.inc | private WordLevelDiff::split($lines) |
Parameters
$lines:
Return value
array:
File
- includes/
diff.inc, line 923 - A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
Class
- WordLevelDiff
- @private
Code
private 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) > self::MAX_LINE_LENGTH) {
$words[] = $line;
$stripped[] = $line;
}
else {
$m = array();
if (preg_match_all('/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
$line, $m)
) {
foreach ($m[0] as $word) {
$words[] = $word;
}
foreach ($m[1] as $stripped_word) {
$stripped[] = $stripped_word;
}
}
}
}
return array($words, $stripped);
}