當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CMbString::diff方法代碼示例

本文整理匯總了PHP中CMbString::diff方法的典型用法代碼示例。如果您正苦於以下問題:PHP CMbString::diff方法的具體用法?PHP CMbString::diff怎麽用?PHP CMbString::diff使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CMbString的用法示例。


在下文中一共展示了CMbString::diff方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: diff

 static function diff($before, $after, $mode = "w")
 {
     switch ($mode) {
         case 'c':
             $lb = strlen($before);
             $la = strlen($after);
             break;
         case 'w':
             $before = self::splitString($before, " \t", "\r\n", $posb);
             $lb = count($before);
             $after = self::splitString($after, " \t", "\r\n", $posa);
             $la = count($after);
             break;
         case 'l':
             $before = self::splitString($before, "\r\n", '', $posb);
             $lb = count($before);
             $after = self::splitString($after, "\r\n", '', $posa);
             $la = count($after);
             break;
         default:
             return false;
     }
     $diff = array();
     for ($b = $a = 0; $b < $lb && $a < $la;) {
         for ($pb = $b; $a < $la && $pb < $lb && $after[$a] === $before[$pb]; ++$a, ++$pb) {
         }
         if ($pb !== $b) {
             $diff[] = array('change' => '=', 'position' => $mode === 'c' ? $b : $posb[$b], 'length' => $mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]);
             $b = $pb;
         }
         if ($b === $lb) {
             break;
         }
         for ($pb = $b; $pb < $lb; ++$pb) {
             for ($pa = $a; $pa < $la && $after[$pa] !== $before[$pb]; ++$pa) {
             }
             if ($pa !== $la) {
                 break;
             }
         }
         if ($pb !== $b) {
             $diff[] = array('change' => '-', 'position' => $mode === 'c' ? $b : $posb[$b], 'length' => $mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]);
             $b = $pb;
         }
         if ($pa !== $a) {
             $position = $mode === 'c' ? $a : $posa[$a];
             $length = $mode === 'c' ? $pa - $a : $posa[$pa] - $posa[$a];
             $change = array('change' => '+', 'position' => $position, 'length' => $length);
             $diff[] = $change;
             $a = $pa;
         }
     }
     if ($a < $la) {
         $position = $mode === 'c' ? $a : $posa[$a];
         $length = $mode === 'c' ? $la - $a : $posa[$la] - $posa[$a];
         $change = array('change' => '+', 'position' => $position, 'length' => $length);
         $diff[] = $change;
     }
     return self::$diff = $diff;
 }
開發者ID:fbone,項目名稱:mediboard4,代碼行數:60,代碼來源:CMbString.class.php


注:本文中的CMbString::diff方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。