> Nepotkal se někdo s PHP scriptem který by uměl u dvou souborů najít v > čem se liší. 5 min :-))) kdyz vis co hledas (algoritmus DIFF) Modified: lib difflib.php Log: add 'all()' method Revision Changes Path 1.8 +27 -7 moniwiki/lib/difflib.php Index: difflib.php =================================================================== RCS file: /cvsroot/moniwiki/moniwiki/lib/difflib.php,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- difflib.php 16 Nov 2004 13:31:50 -0000 1.7 +++ difflib.php 17 Oct 2005 16:09:04 -0000 1.8 @@ -8,7 +8,7 @@ // // FIXME: possibly remove assert()'s for production version? -// $Id: difflib.php,v 1.7 2004/11/16 13:31:50 wkpark Exp $ +// $Id: difflib.php,v 1.8 2005/10/17 16:09:04 wkpark Exp $ // original Id: difflib.php,v 1.5 2002/01/21 06:55:47 dairiki Exp // PHP3 does not have assert() @@ -852,14 +852,18 @@ $this->_line = ''; $this->_group = ''; $this->_tag = ''; + $this->_tag_del_open="<del class='diff-removed'>"; + $this->_tag_del_close="</del>"; + $this->_tag_ins_open="<ins class='diff-added'>"; + $this->_tag_ins_close="</ins>"; } function _flushGroup ($new_tag) { if ($this->_group !== '') { if ($this->_tag == 'del') - $this->_line .= "<del class='diff-removed'>$this->_group</del>"; + $this->_line .= $this->_tag_del_open.$this->_group.$this->_tag_del_close; else if ($this->_tag == 'ins') - $this->_line .= "<ins class='diff-added'>$this->_group</ins>"; + $this->_line .= $this->_tag_ins_open.$this->_group.$this->_tag_ins_close; else $this->_line .= $this->_group; } @@ -900,17 +904,17 @@ class WordLevelDiff extends MappedDiff { - function WordLevelDiff ($orig_lines, $_final_lines,$charset="euc-kr") { + function WordLevelDiff ($orig_lines, $final_lines,$charset="euc-kr") { if (strtolower($charset) == 'euc-kr') # two bytes sequence rule $this->charset_rule='[\xb0-\xfd][\xa1-\xfe]|'; else if (strtolower($charset) == 'utf-8') # three bytes sequence $this->charset_rule='[\xE1-\xEF][\x80-\xBF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|'; list ($orig_words, $orig_stripped) = $this->_split($orig_lines); - list ($_final_words, $_final_stripped) = $this->_split($_final_lines); + list ($final_words, $final_stripped) = $this->_split($final_lines); - $this->MappedDiff($orig_words, $_final_words, - $orig_stripped, $_final_stripped); + $this->MappedDiff($orig_words, $final_words, + $orig_stripped, $final_stripped); } function _split($lines) { @@ -947,6 +951,22 @@ } return $_final->getLines(); } + function all () { + $text = new _HWLDF_WordAccumulator; + + foreach ($this->edits as $edit) { + if ($edit->type == 'copy') + $text->addWords($edit->orig); + else { + #print "$edit->type:"; + if ($edit->orig) + $text->addWords($edit->orig, 'del'); + if ($edit->_final) + $text->addWords($edit->_final, 'ins'); + } + } + return $text->getLines(); + } } /** $d=new Diff($stary,$novy); // napr. pres file() $f=new DiffFormatter(); echo $f->format($d); DFlyReceived on Mon, 7 Aug 2006 22:25:56 +0200
This archive was generated by hypermail 2.1.8 : 07. 08. 2006, 22:26 CEST