Exemple #1
0
 /**
  *
  * @param string $source
  * @param int $startPos
  * @return array
  */
 public function getNextObjectFromString($source, $startPos)
 {
     $nextToken = $this->lexer->getNextTokenFromString($source, $startPos);
     while ($nextToken->tokenName === 'white_space') {
         $startPos = $nextToken->newPos;
         $nextToken = $this->lexer->getNextTokenFromString($source, $startPos);
     }
     $value = '';
     $endPos = 0;
     switch ($nextToken->tokenName) {
         case 'numeric':
         case 'string':
         case 'boolean':
         case 'null':
             // value is $token content, expected are white space (optional) + endobj
             $value = substr($source, $startPos, $nextToken->newPos - $startPos);
             $endPos = $nextToken->newPos;
             break;
         case 'dictionary_start':
             // Dictionary. Find next balanced dictionary_end and use
             // DictionaryParser to parse the tokens into a PdfDictionary
             // object
             $dictionaryIndent = 1;
             $tmpPos = $nextToken->newPos;
             $mytoken = $this->lexer->getNextTokenFromString($source, $tmpPos);
             while ($mytoken->tokenName !== 'dictionary_end' || $dictionaryIndent > 0) {
                 if ($mytoken->tokenName === 'dictionary_start') {
                     $dictionaryIndent++;
                 } elseif ($mytoken->tokenName === 'dictionary_end') {
                     $dictionaryIndent--;
                 }
                 if ($dictionaryIndent === 0 && $mytoken->tokenName === 'dictionary_end') {
                     break;
                 }
                 $tmpPos = $mytoken->newPos;
                 $mytoken = $this->lexer->getNextTokenFromString($source, $tmpPos);
             }
             $value = $this->dictionaryParser->parse(substr($source, $startPos, $mytoken->newPos - $startPos));
             $endPos = $mytoken->newPos;
             break;
     }
     return array($endPos, $value);
 }