コード例 #1
0
 static function f_Loc_PrmRead(&$Txt, $Pos, $XmlTag, $DelimChrs, $BegStr, $EndStr, &$Loc, &$PosEnd, $WithPos = false)
 {
     $BegLen = strlen($BegStr);
     $BegChr = $BegStr[0];
     $BegIs1 = $BegLen === 1;
     $DelimIdx = false;
     $DelimCnt = 0;
     $DelimChr = '';
     $BegCnt = 0;
     $SubName = $Loc->SubOk;
     $Status = 0;
     // 0: name not started, 1: name started, 2: name ended, 3: equal found, 4: value started
     $PosName = 0;
     $PosNend = 0;
     $PosVal = 0;
     // Variables for checking the loop
     $PosEnd = strpos($Txt, $EndStr, $Pos);
     if ($PosEnd === false) {
         return;
     }
     $Continue = $Pos < $PosEnd;
     while ($Continue) {
         $Chr = $Txt[$Pos];
         if ($DelimIdx) {
             // Reading in the string
             if ($Chr === $DelimChr) {
                 // Quote found
                 if ($Chr === $Txt[$Pos + 1]) {
                     // Double Quote => the string continue with un-double the quote
                     $Pos++;
                 } else {
                     // Simple Quote => end of string
                     $DelimIdx = false;
                 }
             }
         } else {
             // Reading outside the string
             if ($BegCnt === 0) {
                 // Analyzing parameters
                 $CheckChr = false;
                 if ($Chr === ' ' or $Chr === "\r" or $Chr === "\n") {
                     if ($Status === 1) {
                         if ($SubName and $XmlTag === false) {
                             // Accept spaces in TBS subname.
                         } else {
                             $Status = 2;
                             $PosNend = $Pos;
                         }
                     } elseif ($XmlTag and $Status === 4) {
                         clsTinyButStrong::f_Loc_PrmCompute($Txt, $Loc, $SubName, $Status, $XmlTag, $DelimChr, $DelimCnt, $PosName, $PosNend, $PosVal, $Pos, $WithPos);
                         $Status = 0;
                     }
                 } elseif ($XmlTag === false and $Chr === ';') {
                     clsTinyButStrong::f_Loc_PrmCompute($Txt, $Loc, $SubName, $Status, $XmlTag, $DelimChr, $DelimCnt, $PosName, $PosNend, $PosVal, $Pos, $WithPos);
                     $Status = 0;
                 } elseif ($Status === 4) {
                     $CheckChr = true;
                 } elseif ($Status === 3) {
                     $Status = 4;
                     $DelimCnt = 0;
                     $PosVal = $Pos;
                     $CheckChr = true;
                 } elseif ($Status === 2) {
                     if ($Chr === '=') {
                         $Status = 3;
                     } elseif ($XmlTag) {
                         clsTinyButStrong::f_Loc_PrmCompute($Txt, $Loc, $SubName, $Status, $XmlTag, $DelimChr, $DelimCnt, $PosName, $PosNend, $PosVal, $Pos, $WithPos);
                         $Status = 1;
                         $PosName = $Pos;
                         $CheckChr = true;
                     } else {
                         $Status = 4;
                         $DelimCnt = 0;
                         $PosVal = $Pos;
                         $CheckChr = true;
                     }
                 } elseif ($Status === 1) {
                     if ($Chr === '=') {
                         $Status = 3;
                         $PosNend = $Pos;
                     } else {
                         $CheckChr = true;
                     }
                 } else {
                     $Status = 1;
                     $PosName = $Pos;
                     $CheckChr = true;
                 }
                 if ($CheckChr) {
                     $DelimIdx = strpos($DelimChrs, $Chr);
                     if ($DelimIdx === false) {
                         if ($Chr === $BegChr) {
                             if ($BegIs1) {
                                 $BegCnt++;
                             } elseif (substr($Txt, $Pos, $BegLen) === $BegStr) {
                                 $BegCnt++;
                             }
                         }
                     } else {
                         $DelimChr = $DelimChrs[$DelimIdx];
                         $DelimCnt++;
                         $DelimIdx = true;
                     }
                 }
             } else {
                 if ($Chr === $BegChr) {
                     if ($BegIs1) {
                         $BegCnt++;
                     } elseif (substr($Txt, $Pos, $BegLen) === $BegStr) {
                         $BegCnt++;
                     }
                 }
             }
         }
         // Next char
         $Pos++;
         // We check if it's the end
         if ($Pos === $PosEnd) {
             if ($XmlTag) {
                 $Continue = false;
             } elseif ($DelimIdx === false) {
                 if ($BegCnt > 0) {
                     $BegCnt--;
                 } else {
                     $Continue = false;
                 }
             }
             if ($Continue) {
                 $PosEnd = strpos($Txt, $EndStr, $PosEnd + 1);
                 if ($PosEnd === false) {
                     return;
                 }
             } else {
                 if ($XmlTag and $Txt[$Pos - 1] === '/') {
                     $Pos--;
                 }
                 // In case last attribute is stuck to "/>"
                 clsTinyButStrong::f_Loc_PrmCompute($Txt, $Loc, $SubName, $Status, $XmlTag, $DelimChr, $DelimCnt, $PosName, $PosNend, $PosVal, $Pos, $WithPos);
             }
         }
     }
     $PosEnd = $PosEnd + (strlen($EndStr) - 1);
 }