OSDN Git Service

BugTrack/779: Cleanup/Simplify a little
authorhenoheno <henoheno>
Sat, 10 Dec 2005 12:23:24 +0000 (21:23 +0900)
committerhenoheno <henoheno>
Sat, 10 Dec 2005 12:23:24 +0000 (21:23 +0900)
* Rename a define
* Shrink brackets
* Double quotes => Single quotes
* Added spaces
* Japanese => English
* preg_replace() => str_replace()

lib/diff.php

index 31b4491..65d5b79 100644 (file)
@@ -1,15 +1,16 @@
 <?php
 // PukiWiki - Yet another WikiWikiWeb clone.
-// $Id: diff.php,v 1.5 2005/04/30 05:21:00 henoheno Exp $
+// $Id: diff.php,v 1.6 2005/12/10 12:23:24 henoheno Exp $
 // Copyright (C)
 //   2003-2005 PukiWiki Developers Team
 //   2001-2002 Originally written by yu-ji
 // License: GPL v2 or (at your option) any later version
 //
-//¾×ÆÍ»þ¤ËÂбþɽ¤ò½Ð¤¹
-define('DIFF_SHOW_TABLE',TRUE);
 
-// º¹Ê¬¤ÎºîÀ®
+// Show more information when it conflicts
+define('PKWK_DIFF_SHOW_CONFLICT_DETAIL', 1);
+
+// Create diff-style data between arrays
 function do_diff($strlines1, $strlines2)
 {
        $obj = new line_diff();
@@ -17,7 +18,7 @@ function do_diff($strlines1, $strlines2)
        return $str;
 }
 
-// º¹Ê¬¤ÎºîÀ®(¹¹¿·¤Î¾×ÆÍ)
+// Merge helper (when it conflicts)
 function do_update_diff($pagestr, $poststr, $original)
 {
        $obj = new line_diff();
@@ -32,8 +33,7 @@ function do_update_diff($pagestr, $poststr, $original)
 
        $arr = $obj->arr_compare('all', $diff1, $diff2);
 
-       if (DIFF_SHOW_TABLE)
-       {
+       if (PKWK_DIFF_SHOW_CONFLICT_DETAIL) {
                global $do_update_diff_table;
 
                $do_update_diff_table = <<<EOD
@@ -47,18 +47,19 @@ function do_update_diff($pagestr, $poststr, $original)
  </tr>
 EOD;
                $tags = array('th', 'th', 'td');
-               foreach ($arr as $_obj)
-               {
+               foreach ($arr as $_obj) {
                        $do_update_diff_table .= '<tr>';
                        $params = array($_obj->get('left'), $_obj->get('right'), $_obj->text());
                        foreach ($params as $key=>$text) {
                                $text = htmlspecialchars($text);
                                if (trim($text) == '') $text = '&nbsp;';
-                               $do_update_diff_table .= "<{$tags[$key]} class=\"style_{$tags[$key]}\">$text</{$tags[$key]}>";
+                               $do_update_diff_table .= '<' . $tags[$key] .
+                                       ' class="style_' . $tags[$key] . '">' . $text .
+                                       '</' . $tags[$key] . '>';
                        }
-                       $do_update_diff_table .= '</tr>'."\n";
+                       $do_update_diff_table .= '</tr>' . "\n";
                }
-               $do_update_diff_table .= '</table>'."\n";
+               $do_update_diff_table .= '</table>' . "\n";
        }
 
        $body = '';
@@ -72,19 +73,13 @@ EOD;
        return array(rtrim($body) . "\n", $auto);
 }
 
-/*
-line_diff¥¯¥é¥¹
-
-°Ê²¼¤Î¾ðÊó¤ò»²¹Í¤Ë¤·¤ÆºîÀ®¤·¤Þ¤·¤¿¡£
-
-S. Wu, <A HREF="http://www.cs.arizona.edu/people/gene/vita.html">
-E. Myers,</A> U. Manber, and W. Miller,
-<A HREF="http://www.cs.arizona.edu/people/gene/PAPERS/np_diff.ps">
-"An O(NP) Sequence Comparison Algorithm,"</A>
-Information Processing Letters 35, 6 (1990), 317-323.
-
-*/
 
+// References of this class:
+// S. Wu, <A HREF="http://www.cs.arizona.edu/people/gene/vita.html">
+// E. Myers,</A> U. Manber, and W. Miller,
+// <A HREF="http://www.cs.arizona.edu/people/gene/PAPERS/np_diff.ps">
+// "An O(NP) Sequence Comparison Algorithm,"</A>
+// Information Processing Letters 35, 6 (1990), 317-323.
 class line_diff
 {
        var $arr1, $arr2, $m, $n, $pos, $key, $plus, $minus, $equal, $reverse;
@@ -111,8 +106,8 @@ class line_diff
                $this->key  = $key;
                $this->arr1 = array();
                $this->arr2 = array();
-               $str1 = preg_replace("/\r/",'',$str1);
-               $str2 = preg_replace("/\r/",'',$str2);
+               $str1 = str_replace("\r", '', $str1);
+               $str2 = str_replace("\r", '', $str2);
                foreach (explode("\n", $str1) as $line) {
                        $this->arr1[] = new DiffLine($line);
                }
@@ -138,12 +133,12 @@ class line_diff
                $this->m = count($this->arr1);
                $this->n = count($this->arr2);
 
-               if ($this->m == 0 || $this->n == 0) { // no need compare.
+               if ($this->m == 0 || $this->n == 0) { // No need to compare
                        $this->result = array(array('x'=>0, 'y'=>0));
                        return;
                }
 
-               // sentinel
+               // Sentinel
                array_unshift($this->arr1, new DiffLine(''));
                $this->m++;
                array_unshift($this->arr2, new DiffLine(''));
@@ -205,7 +200,7 @@ class line_diff
        function toArray()
        {
                $arr = array();
-               if ($this->reverse) { //¸È©¤Ê¡Ä
+               if ($this->reverse) { // ¸È©¤Ê¡Ä
                        $_x = 'y'; $_y = 'x'; $_m = $this->n; $arr1 =& $this->arr2; $arr2 =& $this->arr1;
                } else {
                        $_x = 'x'; $_y = 'y'; $_m = $this->m; $arr1 =& $this->arr1; $arr2 =& $this->arr2;
@@ -246,7 +241,7 @@ class DiffLine
 
        function DiffLine($text)
        {
-               $this->text   = "$text\n";
+               $this->text   = $text . "\n";
                $this->status = array();
        }