Exemplo n.º 1
0
 public function generate($oldText, $newText)
 {
     $patch = parent::generate($oldText, $newText);
     $opList = array();
     foreach ($patch as $op) {
         if ($op instanceof LogootIns) {
             $opList[] = LogootPlusIns::plus($op);
         } elseif ($op instanceof LogootDel) {
             $opList[] = LogootPlusDel::plus($op);
         }
     }
     $p = new LogootPatch($patch->getId(), $opList);
     $p->applied();
     return $p;
 }
Exemplo n.º 2
0
 public function generate($oldText, $newText)
 {
     $this->clock = utils::getNextClock();
     wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate ');
     /* explode into lines */
     $ota = explode("\n", $oldText);
     $nta = explode("\n", $newText);
     $counter = 0;
     if (count($ota) == 1 && $ota[0] == "") {
         // c'est un nouveau document
         unset($ota[0]);
         wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - création ');
         $listOp = $this->generate_ins_text(1, $nta);
         return $listOp;
     } else {
         list($trouve, $deb, $fin) = $this->locate($ota, $nta);
         if ($trouve) {
             //il y a eu un ajout de texte au début et/ou à la fin uniquement
             $listOp = new LogootPatch($this->sessionid . $this->clock);
             if ($deb > 0) {
                 wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - ajout au début ');
                 $listOp1 = $this->generate_ins_text(1, array_slice($nta, 0, $deb));
                 $listOp->addPatch($listOp1);
                 $delta = $listOp1->size();
             } else {
                 $delta = 0;
             }
             if ($fin + 1 < count($nta)) {
                 wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - ajout à la fin ');
                 $listOp2 = $this->generate_ins_text(count($ota) + 1 + $delta, array_slice($nta, $fin + 1, count($nta) - ($fin + 1)));
                 $listOp->addPatch($listOp2);
             }
             return $listOp;
         } else {
             $listOp = new LogootPatch($this->sessionid . $this->clock);
             $diffs = new Diff1($ota, $nta);
             /* convert 4 operations into 2 operations */
             foreach ($diffs->edits as $operation) {
                 switch ($operation->type) {
                     case "add":
                         $adds = $operation->closing;
                         ksort($adds, SORT_NUMERIC);
                         foreach ($adds as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Ajout ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_ins_line($lineNb, $linetxt));
                             $counter += 1;
                         }
                         break;
                     case "delete":
                         foreach ($operation->orig as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Suppression ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_del_line($lineNb + $counter, $linetxt));
                             $counter -= 1;
                         }
                         break;
                     case "change":
                         foreach ($operation->orig as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Change/Suppression ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_del_line($lineNb + $counter, $linetxt));
                             $counter -= 1;
                         }
                         $adds1 = $operation->closing;
                         ksort($adds1, SORT_NUMERIC);
                         foreach ($adds1 as $lineNb => $linetxt) {
                             wfDebugLog('p2p', $this->clock . ' - function logootEngine::generate - Change/Ajout ' . $linetxt . " (" . $lineNb . ")");
                             $listOp->add($this->generate_ins_line($lineNb, $linetxt));
                             $counter += 1;
                         }
                         break;
                     case "copy":
                         break;
                     default:
                 }
             }
             $listOp->applied();
             return $listOp;
         }
     }
 }