From: <var...@us...> - 2014-12-11 18:01:07
|
Revision: 9442 http://sourceforge.net/p/phpwiki/code/9442 Author: vargenau Date: 2014-12-11 18:00:59 +0000 (Thu, 11 Dec 2014) Log Message: ----------- Add public/protected/private Modified Paths: -------------- trunk/lib/diff.php trunk/lib/diff3.php trunk/lib/difflib.php Modified: trunk/lib/diff.php =================================================================== --- trunk/lib/diff.php 2014-12-10 17:54:49 UTC (rev 9441) +++ trunk/lib/diff.php 2014-12-11 18:00:59 UTC (rev 9442) @@ -20,7 +20,7 @@ $this->_tag = '~begin'; } - function _flushGroup($new_tag) + private function _flushGroup($new_tag) { if ($this->_group !== false) { if (!$this->_line) @@ -34,7 +34,7 @@ $this->_tag = $new_tag; } - function _flushLine($new_tag) + private function _flushLine($new_tag) { $this->_flushGroup($new_tag); if ($this->_line) @@ -42,7 +42,7 @@ $this->_line = HTML(); } - function addWords($words, $tag = '') + public function addWords($words, $tag = '') { if ($tag != $this->_tag) $this->_flushGroup($tag); @@ -61,7 +61,7 @@ } } - function getLines() + public function getLines() { $this->_flushLine('~done'); return $this->_lines; @@ -79,7 +79,7 @@ $orig_stripped, $final_stripped); } - function _split($lines) + private function _split($lines) { // FIXME: fix POSIX char class. if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs', @@ -91,7 +91,7 @@ return array($m[0], $m[1]); } - function orig() + public function orig() { $orig = new _HWLDF_WordAccumulator; @@ -104,7 +104,7 @@ return $orig->getLines(); } - function _final() + public function _final() { $final = new _HWLDF_WordAccumulator; @@ -143,31 +143,31 @@ parent::__construct($context_lines); } - function _start_diff() + protected function _start_diff() { $this->_top = HTML::div(array('class' => 'diff')); } - function _end_diff() + protected function _end_diff() { $val = $this->_top; unset($this->_top); return $val; } - function _start_block($header) + protected function _start_block($header) { $this->_block = HTML::div(array('class' => 'block'), HTML::samp($header)); } - function _end_block() + protected function _end_block() { $this->_top->pushContent($this->_block); unset($this->_block); } - function _lines($lines, $class, $prefix = false, $elem = false) + protected function _lines($lines, $class, $prefix = false, $elem = false) { if (!$prefix) $prefix = HTML::raw(' '); @@ -183,22 +183,22 @@ $this->_block->pushContent($div); } - function _context($lines) + protected function _context($lines) { $this->_lines($lines, 'context'); } - function _deleted($lines) + protected function _deleted($lines) { $this->_lines($lines, 'deleted', '-', 'del'); } - function _added($lines) + protected function _added($lines) { $this->_lines($lines, 'added', '+', 'ins'); } - function _changed($orig, $final) + protected function _changed($orig, $final) { $diff = new WordLevelDiff($orig, $final); $this->_lines($diff->orig(), 'original', '-'); Modified: trunk/lib/diff3.php =================================================================== --- trunk/lib/diff3.php 2014-12-10 17:54:49 UTC (rev 9441) +++ trunk/lib/diff3.php 2014-12-11 18:00:59 UTC (rev 9442) @@ -21,7 +21,7 @@ $this->final2 = $final2 ? $final2 : array(); } - function merged() + protected function merged() { if (!isset($this->_merged)) { if ($this->final1 === $this->final2) @@ -34,7 +34,7 @@ return $this->_merged; } - function is_conflict() + protected function is_conflict() { return $this->merged() === false; } @@ -51,12 +51,12 @@ $this->final2 = &$this->orig; } - function merged() + protected function merged() { return $this->orig; } - function is_conflict() + protected function is_conflict() { return false; } @@ -73,40 +73,42 @@ $this->_init(); } - function _init() + private function _init() { - $this->orig = $this->final1 = $this->final2 = array(); + $this->orig = array(); + $this->final1 = array(); + $this->final2 = array(); } - function _append(&$array, $lines) + private function _append(&$array, $lines) { array_splice($array, sizeof($array), 0, $lines); } - function input($lines) + public function input($lines) { if ($lines) $this->_append($this->orig, $lines); } - function out1($lines) + public function out1($lines) { if ($lines) $this->_append($this->final1, $lines); } - function out2($lines) + public function out2($lines) { if ($lines) $this->_append($this->final2, $lines); } - function is_empty() + private function is_empty() { return !$this->orig && !$this->final1 && !$this->final2; } - function finish() + public function finish() { if ($this->is_empty()) return false; @@ -128,7 +130,7 @@ $eng->diff($orig, $final2)); } - function __diff3($edits1, $edits2) + private function __diff3($edits1, $edits2) { $blocks = array(); $bb = new _Diff3_BlockBuilder; @@ -136,11 +138,6 @@ $e1 = current($edits1); $e2 = current($edits2); while ($e1 || $e2) { -// echo "====\n"; -// print_r($e1); -// print_r($e2); -// echo "====\n"; - if ($e1 && $e2 && $e1->type == 'copy' && $e2->type == 'copy') { // We have copy blocks from both diffs. This is the (only) // time we want to emit a diff3 copy block. @@ -195,7 +192,7 @@ return $blocks; } - function merged_output($label1 = false, $label2 = false) + public function merged_output($label1 = false, $label2 = false) { $lines = array(); foreach ($this->blocks as $block) { Modified: trunk/lib/difflib.php =================================================================== --- trunk/lib/difflib.php 2014-12-10 17:54:49 UTC (rev 9441) +++ trunk/lib/difflib.php 2014-12-11 18:00:59 UTC (rev 9442) @@ -14,14 +14,14 @@ public $orig; public $final; - abstract function reverse(); + abstract public function reverse(); - function norig() + public function norig() { return $this->orig ? sizeof($this->orig) : 0; } - function nfinal() + public function nfinal() { return $this->final ? sizeof($this->final) : 0; } @@ -39,7 +39,7 @@ $this->final = $final; } - function reverse() + public function reverse() { return new _DiffOp_Copy($this->final, $this->orig); } @@ -55,7 +55,7 @@ $this->final = false; } - function reverse() + public function reverse() { return new _DiffOp_Add($this->orig); } @@ -71,7 +71,7 @@ $this->orig = false; } - function reverse() + public function reverse() { return new _DiffOp_Delete($this->final); } @@ -87,7 +87,7 @@ $this->final = $final; } - function reverse() + public function reverse() { return new _DiffOp_Change($this->final, $this->orig); } @@ -125,7 +125,7 @@ public $seq; public $in_seq; - function diff($from_lines, $to_lines) + public function diff($from_lines, $to_lines) { $n_from = sizeof($from_lines); $n_to = sizeof($to_lines); @@ -229,7 +229,7 @@ * match. The caller must trim matching lines from the beginning and end * of the portions it is going to specify. */ - function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) + private function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) { $flip = false; @@ -303,7 +303,7 @@ return array($this->lcs, $seps); } - function _lcs_pos($ypos) + private function _lcs_pos($ypos) { $end = $this->lcs; if ($end == 0 || $ypos > $this->seq[$end]) { @@ -340,7 +340,7 @@ * Note that XLIM, YLIM are exclusive bounds. * All line numbers are origin-0 and discarded lines are not counted. */ - function _compareseq($xoff, $xlim, $yoff, $ylim) + private function _compareseq($xoff, $xlim, $yoff, $ylim) { // Slide down the bottom initial diagonal. while ($xoff < $xlim && $yoff < $ylim @@ -397,7 +397,7 @@ * * This is extracted verbatim from analyze.c (GNU diffutils-2.7). */ - function _shift_boundaries($lines, &$changed, $other_changed) + private function _shift_boundaries($lines, &$changed, $other_changed) { $i = 0; $j = 0; @@ -526,35 +526,14 @@ { $eng = new _DiffEngine; $this->edits = $eng->diff($from_lines, $to_lines); - //$this->_check($from_lines, $to_lines); } /** - * Compute reversed Diff. - * - * SYNOPSIS: - * - * $diff = new Diff($lines1, $lines2); - * $rev = $diff->reverse(); - * @return object A Diff object representing the inverse of the - * original diff. - */ - function reverse() - { - $rev = $this; - $rev->edits = array(); - foreach ($this->edits as $edit) { - $rev->edits[] = $edit->reverse(); - } - return $rev; - } - - /** * Check for empty diff. * * @return bool True iff two sequences were identical. */ - function isEmpty() + public function isEmpty() { foreach ($this->edits as $edit) { if ($edit->type != 'copy') @@ -564,23 +543,6 @@ } /** - * Compute the length of the Longest Common Subsequence (LCS). - * - * This is mostly for diagnostic purposed. - * - * @return int The length of the LCS. - */ - function lcs() - { - $lcs = 0; - foreach ($this->edits as $edit) { - if ($edit->type == 'copy') - $lcs += sizeof($edit->orig); - } - return $lcs; - } - - /** * Get the original set of lines. * * This reconstructs the $from_lines parameter passed to the @@ -588,7 +550,7 @@ * * @return array The original sequence of strings. */ - function orig() + public function orig() { $lines = array(); @@ -607,7 +569,7 @@ * * @return array The sequence of strings. */ - function _final() + public function _final() { $lines = array(); @@ -617,37 +579,6 @@ } return $lines; } - - /** - * Check a Diff for validity. - * - * This is here only for debugging purposes. - * @param string $from_lines - * @param string $to_lines - */ - function _check($from_lines, $to_lines) - { - if (serialize($from_lines) != serialize($this->orig())) - trigger_error("Reconstructed original doesn't match", E_USER_ERROR); - if (serialize($to_lines) != serialize($this->_final())) - trigger_error("Reconstructed final doesn't match", E_USER_ERROR); - - $rev = $this->reverse(); - if (serialize($to_lines) != serialize($rev->orig())) - trigger_error("Reversed original doesn't match", E_USER_ERROR); - if (serialize($from_lines) != serialize($rev->_final())) - trigger_error("Reversed final doesn't match", E_USER_ERROR); - - $prevtype = 'none'; - foreach ($this->edits as $edit) { - if ($prevtype == $edit->type) - trigger_error("Edit sequence is non-optimal", E_USER_ERROR); - $prevtype = $edit->type; - } - - $lcs = $this->lcs(); - trigger_error("Diff okay: LCS = $lcs", E_USER_NOTICE); - } } /** @@ -738,7 +669,7 @@ * @param $diff object A Diff object. * @return string The formatted output. */ - function format($diff) + public function format($diff) { $xi = $yi = 1; @@ -793,7 +724,7 @@ return $this->_end_diff(); } - function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) + private function _block($xbeg, $xlen, $ybeg, $ylen, &$edits) { $this->_start_block($this->_block_header($xbeg, $xlen, $ybeg, $ylen)); foreach ($edits as $edit) { @@ -808,19 +739,19 @@ $this->_end_block(); } - function _start_diff() + protected function _start_diff() { ob_start(); } - function _end_diff() + protected function _end_diff() { $val = ob_get_contents(); ob_end_clean(); return $val; } - function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function _block_header($xbeg, $xlen, $ybeg, $ylen) { if ($xlen > 1) $xbeg .= "," . ($xbeg + $xlen - 1); @@ -830,37 +761,37 @@ return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; } - function _start_block($header) + protected function _start_block($header) { echo $header; } - function _end_block() + protected function _end_block() { } - function _lines($lines, $prefix = ' ') + protected function _lines($lines, $prefix = ' ') { foreach ($lines as $line) echo "$prefix $line\n"; } - function _context($lines) + protected function _context($lines) { $this->_lines($lines); } - function _added($lines) + protected function _added($lines) { $this->_lines($lines, ">"); } - function _deleted($lines) + protected function _deleted($lines) { $this->_lines($lines, "<"); } - function _changed($orig, $final) + protected function _changed($orig, $final) { $this->_deleted($orig); echo "---\n"; @@ -881,7 +812,7 @@ $this->trailing_context_lines = $context_lines; } - function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function _block_header($xbeg, $xlen, $ybeg, $ylen) { if ($xlen != 1) $xbeg .= "," . $xlen; @@ -890,17 +821,17 @@ return "@@ -$xbeg +$ybeg @@\n"; } - function _added($lines) + protected function _added($lines) { $this->_lines($lines, "+"); } - function _deleted($lines) + protected function _deleted($lines) { $this->_lines($lines, "-"); } - function _changed($orig, $final) + protected function _changed($orig, $final) { $this->_deleted($orig); $this->_added($final); @@ -926,7 +857,7 @@ $this->trailing_context_lines = $context_lines; } - function _lines($lines, $prefix = '') + protected function _lines($lines, $prefix = '') { if (!$prefix == '') echo "$prefix\n"; @@ -936,22 +867,22 @@ echo "$prefix\n"; } - function _added($lines) + protected function _added($lines) { $this->_lines($lines, ">>>>>>>"); } - function _deleted($lines) + protected function _deleted($lines) { $this->_lines($lines, "<<<<<<<"); } - function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function _block_header($xbeg, $xlen, $ybeg, $ylen) { return ""; } - function _changed($orig, $final) + protected function _changed($orig, $final) { $this->_deleted($orig); $this->_added($final); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |