/** * */ public function testDictCornerCasesParser() { $parser = new DictionaryParser(); $dict = $parser->parse(file_get_contents(__DIR__ . '/data/dictionaries/corner-cases.dict')); $this->assertEquals(array('/foo', '/', '/1', '/2', '/3', '/4', '/5', '/6', '/8', '/9', '/10'), $dict->getKeys()); $subdict = $dict->get('/foo'); $this->assertEquals(array(), $subdict->getKeys()); $array = $dict->get('/10'); $this->assertEquals(true, is_array($array)); $this->assertEquals(6, count($array)); }
/** * * @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); }