diff options
Diffstat (limited to 'phpBB/includes/diff/engine.php')
-rw-r--r-- | phpBB/includes/diff/engine.php | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/phpBB/includes/diff/engine.php b/phpBB/includes/diff/engine.php index e7740a0584..456b5233d3 100644 --- a/phpBB/includes/diff/engine.php +++ b/phpBB/includes/diff/engine.php @@ -47,11 +47,32 @@ if (!defined('IN_PHPBB')) */ class diff_engine { - function diff($from_lines, $to_lines) + function diff(&$from_lines, &$to_lines, $preserve_cr = true) { // Remove empty lines... -// array_walk($from_lines, array('diff', 'trim_newlines')); -// array_walk($to_lines, array('diff', 'trim_newlines')); + // If preserve_cr is true, we basically only change \r\n and bare \r to \n to get the same carriage returns for both files + // If it is false, we try to only use \n once per line and ommit all empty lines to be able to get a proper data diff + + if (is_array($from_lines)) + { + $from_lines = implode("\n", $from_lines); + } + + if (is_array($to_lines)) + { + $to_lines = implode("\n", $to_lines); + } + + if ($preserve_cr) + { + $from_lines = explode("\n", str_replace("\r", "\n", str_replace("\r\n", "\n", $from_lines))); + $to_lines = explode("\n", str_replace("\r", "\n", str_replace("\r\n", "\n", $to_lines))); + } + else + { + $from_lines = explode("\n", preg_replace('#[\n\r]+#', "\n", $from_lines)); + $to_lines = explode("\n", preg_replace('#[\n\r]+#', "\n", $to_lines)); + } $n_from = sizeof($from_lines); $n_to = sizeof($to_lines); |