From: <var...@us...> - 2016-07-19 14:28:39
|
Revision: 9885 http://sourceforge.net/p/phpwiki/code/9885 Author: vargenau Date: 2016-07-19 14:28:36 +0000 (Tue, 19 Jul 2016) Log Message: ----------- Refactor: rename identifiers starting with underscore Modified Paths: -------------- trunk/lib/diff.php trunk/lib/diff3.php trunk/lib/difflib.php Modified: trunk/lib/diff.php =================================================================== --- trunk/lib/diff.php 2016-07-19 14:27:10 UTC (rev 9884) +++ trunk/lib/diff.php 2016-07-19 14:28:36 UTC (rev 9885) @@ -26,61 +26,61 @@ require_once 'lib/difflib.php'; -class _HWLDF_WordAccumulator +class HWLDF_WordAccumulator { function __construct() { - $this->_lines = array(); - $this->_line = false; - $this->_group = false; - $this->_tag = '~begin'; + $this->lines = array(); + $this->line = false; + $this->group = false; + $this->tag = '~begin'; } - private function _flushGroup($new_tag) + private function flushGroup($new_tag) { - if ($this->_group !== false) { - if (!$this->_line) - $this->_line = HTML(); - $this->_line->pushContent($this->_tag - ? new HtmlElement($this->_tag, - $this->_group) - : $this->_group); + if ($this->group !== false) { + if (!$this->line) + $this->line = HTML(); + $this->line->pushContent($this->tag + ? new HtmlElement($this->tag, + $this->group) + : $this->group); } - $this->_group = ''; - $this->_tag = $new_tag; + $this->group = ''; + $this->tag = $new_tag; } - private function _flushLine($new_tag) + private function flushLine($new_tag) { - $this->_flushGroup($new_tag); - if ($this->_line) - $this->_lines[] = $this->_line; - $this->_line = HTML(); + $this->flushGroup($new_tag); + if ($this->line) + $this->lines[] = $this->line; + $this->line = HTML(); } public function addWords($words, $tag = '') { - if ($tag != $this->_tag) - $this->_flushGroup($tag); + if ($tag != $this->tag) + $this->flushGroup($tag); foreach ($words as $word) { // new-line should only come as first char of word. if ($word === "") continue; if ($word[0] == "\n") { - $this->_group .= " "; - $this->_flushLine($tag); + $this->group .= " "; + $this->flushLine($tag); $word = substr($word, 1); } assert(!strstr($word, "\n")); - $this->_group .= $word; + $this->group .= $word; } } public function getLines() { - $this->_flushLine('~done'); - return $this->_lines; + $this->flushLine('~done'); + return $this->lines; } } @@ -88,13 +88,13 @@ { function __construct($orig_lines, $final_lines) { - list ($orig_words, $orig_stripped) = $this->_split($orig_lines); - list ($final_words, $final_stripped) = $this->_split($final_lines); + list ($orig_words, $orig_stripped) = $this->split_lines($orig_lines); + list ($final_words, $final_stripped) = $this->split_lines($final_lines); parent::__construct($orig_words, $final_words, $orig_stripped, $final_stripped); } - private function _split($lines) + private function split_lines($lines) { // FIXME: fix POSIX char class. if (!preg_match_all('/ ( [^\S\n]+ | [[:alnum:]]+ | . ) (?: (?!< \n) [^\S\n])? /xs', @@ -108,7 +108,7 @@ public function orig() { - $orig = new _HWLDF_WordAccumulator; + $orig = new HWLDF_WordAccumulator(); foreach ($this->edits as $edit) { if ($edit->type == 'copy') @@ -119,9 +119,9 @@ return $orig->getLines(); } - public function _final() + public function finalize() { - $final = new _HWLDF_WordAccumulator; + $final = new HWLDF_WordAccumulator(); foreach ($this->edits as $edit) { if ($edit->type == 'copy') @@ -145,44 +145,44 @@ class HtmlUnifiedDiffFormatter extends UnifiedDiffFormatter { /** - * @var HtmlElement $_top + * @var HtmlElement $top */ - public $_top; + public $top; /** - * @var HtmlElement $_block + * @var HtmlElement $block */ - public $_block; + public $block; function __construct($context_lines = 4) { parent::__construct($context_lines); } - protected function _start_diff() + protected function start_diff() { - $this->_top = HTML::div(array('class' => 'diff')); + $this->top = HTML::div(array('class' => 'diff')); } - protected function _end_diff() + protected function end_diff() { - $val = $this->_top; - unset($this->_top); + $val = $this->top; + unset($this->top); return $val; } - protected function _start_block($header) + protected function start_block($header) { - $this->_block = HTML::div(array('class' => 'block'), + $this->block = HTML::div(array('class' => 'block'), HTML::samp($header)); } - protected function _end_block() + protected function end_block() { - $this->_top->pushContent($this->_block); - unset($this->_block); + $this->top->pushContent($this->block); + unset($this->block); } - protected function _lines($lines, $class, $prefix = false, $elem = false) + protected function lines($lines, $class, $prefix = false, $elem = false) { if (!$prefix) $prefix = HTML::raw(' '); @@ -195,29 +195,29 @@ $prefix), $line, HTML::raw(' '))); } - $this->_block->pushContent($div); + $this->block->pushContent($div); } - protected function _context($lines) + protected function context($lines) { - $this->_lines($lines, 'context'); + $this->lines($lines, 'context'); } - protected function _deleted($lines) + protected function deleted($lines) { - $this->_lines($lines, 'deleted', '-', 'del'); + $this->lines($lines, 'deleted', '-', 'del'); } - protected function _added($lines) + protected function added($lines) { - $this->_lines($lines, 'added', '+', 'ins'); + $this->lines($lines, 'added', '+', 'ins'); } - protected function _changed($orig, $final) + protected function changed($orig, $final) { $diff = new WordLevelDiff($orig, $final); - $this->_lines($diff->orig(), 'original', '-'); - $this->_lines($diff->_final(), 'final', '+'); + $this->lines($diff->orig(), 'original', '-'); + $this->lines($diff->finalize(), 'final', '+'); } } @@ -378,7 +378,7 @@ $new->get('summary')))); } } else { - $fmt = new HtmlUnifiedDiffFormatter; + $fmt = new HtmlUnifiedDiffFormatter(); $html->pushContent($fmt->format($diff)); } Modified: trunk/lib/diff3.php =================================================================== --- trunk/lib/diff3.php 2016-07-19 14:27:10 UTC (rev 9884) +++ trunk/lib/diff3.php 2016-07-19 14:28:36 UTC (rev 9885) @@ -25,7 +25,7 @@ require_once 'lib/difflib.php'; -class _Diff3_Block +class Diff3_Block { public $type = 'diff3'; @@ -38,17 +38,17 @@ public function merged() { - if (!isset($this->_merged)) { + if (!isset($this->merged)) { if ($this->final1 === $this->final2) - $this->_merged = &$this->final1; + $this->merged = &$this->final1; elseif ($this->final1 === $this->orig) - $this->_merged = &$this->final2; + $this->merged = &$this->final2; elseif ($this->final2 === $this->orig) - $this->_merged = &$this->final1; + $this->merged = &$this->final1; else - $this->_merged = false; + $this->merged = false; } - return $this->_merged; + return $this->merged; } public function is_conflict() @@ -57,7 +57,7 @@ } } -class _Diff3_CopyBlock extends _Diff3_Block +class Diff3_CopyBlock extends Diff3_Block { public $type = 'copy'; @@ -79,7 +79,7 @@ } } -class _Diff3_BlockBuilder +class Diff3_BlockBuilder { public $orig; public $final1; @@ -87,17 +87,17 @@ function __construct() { - $this->_init(); + $this->init(); } - private function _init() + private function init() { $this->orig = array(); $this->final1 = array(); $this->final2 = array(); } - private function _append(&$array, $lines) + private function append(&$array, $lines) { array_splice($array, sizeof($array), 0, $lines); } @@ -105,19 +105,19 @@ public function input($lines) { if ($lines) - $this->_append($this->orig, $lines); + $this->append($this->orig, $lines); } public function out1($lines) { if ($lines) - $this->_append($this->final1, $lines); + $this->append($this->final1, $lines); } public function out2($lines) { if ($lines) - $this->_append($this->final2, $lines); + $this->append($this->final2, $lines); } private function is_empty() @@ -130,8 +130,8 @@ if ($this->is_empty()) return false; else { - $block = new _Diff3_Block($this->orig, $this->final1, $this->final2); - $this->_init(); + $block = new Diff3_Block($this->orig, $this->final1, $this->final2); + $this->init(); return $block; } } @@ -141,16 +141,16 @@ { function __construct($orig, $final1, $final2) { - $eng = new _DiffEngine; + $eng = new DiffEngine(); $this->ConflictingBlocks = 0; //Conflict counter - $this->blocks = $this->__diff3($eng->diff($orig, $final1), + $this->blocks = $this->diff3blocks($eng->diff($orig, $final1), $eng->diff($orig, $final2)); } - private function __diff3($edits1, $edits2) + private function diff3blocks($edits1, $edits2) { $blocks = array(); - $bb = new _Diff3_BlockBuilder; + $bb = new Diff3_BlockBuilder(); $e1 = current($edits1); $e2 = current($edits2); @@ -164,7 +164,7 @@ $ncopy = min($e1->norig(), $e2->norig()); assert($ncopy > 0); - $blocks[] = new _Diff3_CopyBlock(array_slice($e1->orig, 0, $ncopy)); + $blocks[] = new Diff3_CopyBlock(array_slice($e1->orig, 0, $ncopy)); if ($e1->norig() > $ncopy) { array_splice($e1->orig, 0, $ncopy); Modified: trunk/lib/difflib.php =================================================================== --- trunk/lib/difflib.php 2016-07-19 14:27:10 UTC (rev 9884) +++ trunk/lib/difflib.php 2016-07-19 14:28:36 UTC (rev 9885) @@ -23,7 +23,7 @@ // // A PHP diff engine for phpwiki. -abstract class _DiffOp +abstract class DiffOp { public $type; public $orig; @@ -42,7 +42,7 @@ } } -class _DiffOp_Copy extends _DiffOp +class DiffOp_Copy extends DiffOp { public $type = 'copy'; @@ -56,11 +56,11 @@ public function reverse() { - return new _DiffOp_Copy($this->final, $this->orig); + return new DiffOp_Copy($this->final, $this->orig); } } -class _DiffOp_Delete extends _DiffOp +class DiffOp_Delete extends DiffOp { public $type = 'delete'; @@ -72,11 +72,11 @@ public function reverse() { - return new _DiffOp_Add($this->orig); + return new DiffOp_Add($this->orig); } } -class _DiffOp_Add extends _DiffOp +class DiffOp_Add extends DiffOp { public $type = 'add'; @@ -88,11 +88,11 @@ public function reverse() { - return new _DiffOp_Delete($this->final); + return new DiffOp_Delete($this->final); } } -class _DiffOp_Change extends _DiffOp +class DiffOp_Change extends DiffOp { public $type = 'change'; @@ -104,7 +104,7 @@ public function reverse() { - return new _DiffOp_Change($this->final, $this->orig); + return new DiffOp_Change($this->final, $this->orig); } } @@ -128,7 +128,7 @@ * @author Geoffrey T. Dairiki * @access private */ -class _DiffEngine +class DiffEngine { public $xchanged; public $ychanged; @@ -187,11 +187,11 @@ } // Find the LCS. - $this->_compareseq(0, sizeof($this->xv), 0, sizeof($this->yv)); + $this->compareseq(0, sizeof($this->xv), 0, sizeof($this->yv)); // Merge edits when possible - $this->_shift_boundaries($from_lines, $this->xchanged, $this->ychanged); - $this->_shift_boundaries($to_lines, $this->ychanged, $this->xchanged); + $this->shift_boundaries($from_lines, $this->xchanged, $this->ychanged); + $this->shift_boundaries($to_lines, $this->ychanged, $this->xchanged); // Compute the edit operations. $edits = array(); @@ -208,7 +208,7 @@ ++$yi; } if ($copy) - $edits[] = new _DiffOp_Copy($copy); + $edits[] = new DiffOp_Copy($copy); // Find deletes & adds. $delete = array(); @@ -220,10 +220,11 @@ $add[] = $to_lines[$yi++]; if ($delete && $add) - $edits[] = new _DiffOp_Change($delete, $add); + $edits[] = new DiffOp_Change($delete, $add); elseif ($delete) - $edits[] = new _DiffOp_Delete($delete); elseif ($add) - $edits[] = new _DiffOp_Add($add); + $edits[] = new DiffOp_Delete($delete); + elseif ($add) + $edits[] = new DiffOp_Add($add); } return $edits; } @@ -244,7 +245,7 @@ * match. The caller must trim matching lines from the beginning and end * of the portions it is going to specify. */ - private function _diag($xoff, $xlim, $yoff, $ylim, $nchunks) + private function diag($xoff, $xlim, $yoff, $ylim, $nchunks) { $flip = false; @@ -284,7 +285,7 @@ reset($matches); while (list ($junk, $y) = each($matches)) if (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); + $k = $this->lcs_pos($y); assert($k > 0); $ymids[$k] = $ymids[$k - 1]; break; @@ -298,7 +299,7 @@ $this->seq[$k] = $y; $this->in_seq[$y] = 1; } elseif (empty($this->in_seq[$y])) { - $k = $this->_lcs_pos($y); + $k = $this->lcs_pos($y); assert($k > 0); $ymids[$k] = $ymids[$k - 1]; } @@ -318,7 +319,7 @@ return array($this->lcs, $seps); } - private function _lcs_pos($ypos) + private function lcs_pos($ypos) { $end = $this->lcs; if ($end == 0 || $ypos > $this->seq[$end]) { @@ -355,7 +356,7 @@ * Note that XLIM, YLIM are exclusive bounds. * All line numbers are origin-0 and discarded lines are not counted. */ - private function _compareseq($xoff, $xlim, $yoff, $ylim) + private function compareseq($xoff, $xlim, $yoff, $ylim) { // Slide down the bottom initial diagonal. while ($xoff < $xlim && $yoff < $ylim @@ -379,7 +380,7 @@ //$nchunks = max(2,min(8,(int)$nchunks)); $nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1; list ($lcs, $seps) - = $this->_diag($xoff, $xlim, $yoff, $ylim, $nchunks); + = $this->diag($xoff, $xlim, $yoff, $ylim, $nchunks); } if ($lcs == 0) { @@ -394,7 +395,7 @@ reset($seps); $pt1 = $seps[0]; while ($pt2 = next($seps)) { - $this->_compareseq($pt1[0], $pt2[0], $pt1[1], $pt2[1]); + $this->compareseq($pt1[0], $pt2[0], $pt1[1], $pt2[1]); $pt1 = $pt2; } } @@ -412,7 +413,7 @@ * * This is extracted verbatim from analyze.c (GNU diffutils-2.7). */ - private function _shift_boundaries($lines, &$changed, $other_changed) + private function shift_boundaries($lines, &$changed, $other_changed) { $i = 0; $j = 0; @@ -538,7 +539,7 @@ */ function __construct($from_lines, $to_lines) { - $eng = new _DiffEngine; + $eng = new DiffEngine(); $this->edits = $eng->diff($from_lines, $to_lines); } @@ -583,7 +584,7 @@ * * @return array The sequence of strings. */ - public function _final() + public function finalize() { $lines = array(); @@ -691,7 +692,7 @@ $nlead = $this->leading_context_lines; $ntrail = $this->trailing_context_lines; - $this->_start_diff(); + $this->start_diff(); $x0 = 0; $y0 = 0; @@ -703,9 +704,9 @@ } else { if ($ntrail) { $context = array_slice($edit->orig, 0, $ntrail); - $block[] = new _DiffOp_Copy($context); + $block[] = new DiffOp_Copy($context); } - $this->_block($x0, $ntrail + $xi - $x0, + $this->block($x0, $ntrail + $xi - $x0, $y0, $ntrail + $yi - $y0, $block); $block = false; @@ -719,7 +720,7 @@ $y0 = $yi - sizeof($context); $block = array(); if ($context) - $block[] = new _DiffOp_Copy($context); + $block[] = new DiffOp_Copy($context); } $block[] = $edit; } @@ -731,41 +732,44 @@ } if (is_array($block)) - $this->_block($x0, $xi - $x0, + $this->block($x0, $xi - $x0, $y0, $yi - $y0, $block); - return $this->_end_diff(); + return $this->end_diff(); } - private 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)); + $this->start_block($this->block_header($xbeg, $xlen, $ybeg, $ylen)); foreach ($edits as $edit) { if ($edit->type == 'copy') - $this->_context($edit->orig); + $this->context($edit->orig); elseif ($edit->type == 'add') - $this->_added($edit->final); elseif ($edit->type == 'delete') - $this->_deleted($edit->orig); elseif ($edit->type == 'change') - $this->_changed($edit->orig, $edit->final); else + $this->added($edit->final); + elseif ($edit->type == 'delete') + $this->deleted($edit->orig); + elseif ($edit->type == 'change') + $this->changed($edit->orig, $edit->final); + else trigger_error("Unknown edit type", E_USER_ERROR); } - $this->_end_block(); + $this->end_block(); } - protected function _start_diff() + protected function start_diff() { ob_start(); } - protected function _end_diff() + protected function end_diff() { $val = ob_get_contents(); ob_end_clean(); return $val; } - protected function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function block_header($xbeg, $xlen, $ybeg, $ylen) { if ($xlen > 1) $xbeg .= "," . ($xbeg + $xlen - 1); @@ -775,41 +779,41 @@ return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg; } - protected function _start_block($header) + protected function start_block($header) { echo $header; } - protected function _end_block() + protected function end_block() { } - protected function _lines($lines, $prefix = ' ') + protected function lines($lines, $prefix = ' ') { foreach ($lines as $line) echo "$prefix $line\n"; } - protected function _context($lines) + protected function context($lines) { - $this->_lines($lines); + $this->lines($lines); } - protected function _added($lines) + protected function added($lines) { - $this->_lines($lines, ">"); + $this->lines($lines, ">"); } - protected function _deleted($lines) + protected function deleted($lines) { - $this->_lines($lines, "<"); + $this->lines($lines, "<"); } - protected function _changed($orig, $final) + protected function changed($orig, $final) { - $this->_deleted($orig); + $this->deleted($orig); echo "---\n"; - $this->_added($final); + $this->added($final); } } @@ -826,7 +830,7 @@ $this->trailing_context_lines = $context_lines; } - protected function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function block_header($xbeg, $xlen, $ybeg, $ylen) { if ($xlen != 1) $xbeg .= "," . $xlen; @@ -835,20 +839,20 @@ return "@@ -$xbeg +$ybeg @@\n"; } - protected function _added($lines) + protected function added($lines) { - $this->_lines($lines, "+"); + $this->lines($lines, "+"); } - protected function _deleted($lines) + protected function deleted($lines) { - $this->_lines($lines, "-"); + $this->lines($lines, "-"); } - protected function _changed($orig, $final) + protected function changed($orig, $final) { - $this->_deleted($orig); - $this->_added($final); + $this->deleted($orig); + $this->added($final); } } @@ -871,7 +875,7 @@ $this->trailing_context_lines = $context_lines; } - protected function _lines($lines, $prefix = '') + protected function lines($lines, $prefix = '') { if (!$prefix == '') echo "$prefix\n"; @@ -881,24 +885,24 @@ echo "$prefix\n"; } - protected function _added($lines) + protected function added($lines) { - $this->_lines($lines, ">>>>>>>"); + $this->lines($lines, ">>>>>>>"); } - protected function _deleted($lines) + protected function deleted($lines) { - $this->_lines($lines, "<<<<<<<"); + $this->lines($lines, "<<<<<<<"); } - protected function _block_header($xbeg, $xlen, $ybeg, $ylen) + protected function block_header($xbeg, $xlen, $ybeg, $ylen) { return ""; } - protected function _changed($orig, $final) + protected function changed($orig, $final) { - $this->_deleted($orig); - $this->_added($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. |