wp/wp-includes/Text/Diff.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   258      * This is here only for debugging purposes.
   258      * This is here only for debugging purposes.
   259      */
   259      */
   260     function _check($from_lines, $to_lines)
   260     function _check($from_lines, $to_lines)
   261     {
   261     {
   262         if (serialize($from_lines) != serialize($this->getOriginal())) {
   262         if (serialize($from_lines) != serialize($this->getOriginal())) {
   263             trigger_error("Reconstructed original does not match", E_USER_ERROR);
   263             throw new Text_Exception("Reconstructed original does not match");
   264         }
   264         }
   265         if (serialize($to_lines) != serialize($this->getFinal())) {
   265         if (serialize($to_lines) != serialize($this->getFinal())) {
   266             trigger_error("Reconstructed final does not match", E_USER_ERROR);
   266             throw new Text_Exception("Reconstructed final does not match");
   267         }
   267         }
   268 
   268 
   269         $rev = $this->reverse();
   269         $rev = $this->reverse();
   270         if (serialize($to_lines) != serialize($rev->getOriginal())) {
   270         if (serialize($to_lines) != serialize($rev->getOriginal())) {
   271             trigger_error("Reversed original does not match", E_USER_ERROR);
   271             throw new Text_Exception("Reversed original does not match");
   272         }
   272         }
   273         if (serialize($from_lines) != serialize($rev->getFinal())) {
   273         if (serialize($from_lines) != serialize($rev->getFinal())) {
   274             trigger_error("Reversed final does not match", E_USER_ERROR);
   274             throw new Text_Exception("Reversed final does not match");
   275         }
   275         }
   276 
   276 
   277         $prevtype = null;
   277         $prevtype = null;
   278         foreach ($this->_edits as $edit) {
   278         foreach ($this->_edits as $edit) {
   279             if ($edit instanceof $prevtype) {
   279             if ($prevtype !== null && $edit instanceof $prevtype) {
   280                 trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
   280                 throw new Text_Exception("Edit sequence is non-optimal");
   281             }
   281             }
   282             $prevtype = get_class($edit);
   282             $prevtype = get_class($edit);
   283         }
   283         }
   284 
   284 
   285         return true;
   285         return true;
   348  * @package Text_Diff
   348  * @package Text_Diff
   349  * @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
   349  * @author  Geoffrey T. Dairiki <dairiki@dairiki.org>
   350  *
   350  *
   351  * @access private
   351  * @access private
   352  */
   352  */
   353 class Text_Diff_Op {
   353 abstract class Text_Diff_Op {
   354 
   354 
   355     var $orig;
   355     var $orig;
   356     var $final;
   356     var $final;
   357 
   357 
   358     function &reverse()
   358     abstract function &reverse();
   359     {
       
   360         trigger_error('Abstract method', E_USER_ERROR);
       
   361     }
       
   362 
   359 
   363     function norig()
   360     function norig()
   364     {
   361     {
   365         return $this->orig ? count($this->orig) : 0;
   362         return $this->orig ? count($this->orig) : 0;
   366     }
   363     }