Parses a hexadecimal string object from the stream reader.

@param StreamReader $streamReader
@return bool|self
774194
public static function parse(StreamReader $streamReader)
    {
        $bufferOffset = $streamReader->getOffset();

        /**
         * @var string $buffer
         * @var int $pos
         */
        while (true) {
            $buffer = $streamReader->getBuffer(false);
            $pos = \strpos($buffer, '>', $bufferOffset);
            if ($pos === false) {
                if (!$streamReader->increaseLength()) {
                    return false;
                }
                continue;
            }

            break;
        }

        $result = \substr($buffer, $bufferOffset, $pos - $bufferOffset);
        $streamReader->setOffset($pos + 1);

        $v = new self;
        $v->value = $result;

        return $v;
    }
925844
public function readByte(Stream $stream)
    {
        $char = $stream->read(1);
        $byte = ord($char);

        return $byte;
    }
1007430
public static function parse($str)
    {
        $bLength = 0;
        if ('b' === $str[0]) {
            $bLength = 1;
        }

        if ('\'' === $str[$bLength]) {
            return str_replace(
                ['\\\\', '\\\''],
                ['\\', '\''],
                substr($str, $bLength + 1, -1)
            );
        } else {
            return self::parseEscapeSequences(substr($str, $bLength + 1, -1), '"');
        }
    }
545181
public function str(string $delimiter): self
    {
        $sub = \mb_strstr($this->value, $delimiter, false, (string) $this->encoding());

        if ($sub === false) {
            throw new SubstringException(\sprintf(
                'Substring "%s" not found',
                $delimiter
            ));
        }

        return new self($sub, $this->encoding);
    }
137503
protected function filter(CommonValueReader $valueReader, Annotation $annotation)
    {
        return $valueReader->asFloat(
                new NumberRange(
                        $annotation->getMinValue(),
                        $annotation->getMaxValue()
                ),
                $annotation->getDecimals()
        );
    }
247677
protected function _parseArgs()
    {
        $cpt = 0;
        $value = $name = '';
        $args = [];
        $body = '';
        while ($token = $this->_stream->current(true)) {
            $body .= $token[1];
            switch ($token[0]) {
                case '(':
                    if ($cpt) {
                        $value .= $token[1];
                    }
                    $cpt++;
                    break;
                case '=':
                    $name = $value;
                    $value = '';
                    break;
                case ')':
                    $cpt--;
                    if ($cpt) {
                        $value .= $token[1];
                        break;
                    }
                    /* Same behavior as comma */
                case ',':
                    $value = trim($value);
                    if ($value !== '') {
                        $name ? $args[trim($name)] = $value : $args[] = $value;
                    }
                    $name = $value = '';
                    break;
                default:
                    $value .= $token[1];
                    break;
            }
            if ($token[1] === ')' && $cpt === 0) {
                break;
            }
            $this->_stream->next();
        }
        return compact('args', 'body');
    }
1026811
static function parseNormalError(\XMLReader $xmlReader)
    {
        $result = array( 'Code' => null, 'Message' => null, 'RequestId' => null, 'HostId' => null );
        while ($xmlReader->Read()) {
            if ($xmlReader->nodeType == \XMLReader::ELEMENT) {
                switch ($xmlReader->name) {
                    case 'Code':
                        $xmlReader->read();
                        if ($xmlReader->nodeType == \XMLReader::TEXT) {
                            $result['Code'] = $xmlReader->value;
                        }
                        break;
                    case 'Message':
                        $xmlReader->read();
                        if ($xmlReader->nodeType == \XMLReader::TEXT) {
                            $result['Message'] = $xmlReader->value;
                        }
                        break;
                    case 'RequestId':
                        $xmlReader->read();
                        if ($xmlReader->nodeType == \XMLReader::TEXT) {
                            $result['RequestId'] = $xmlReader->value;
                        }
                        break;
                    case 'HostId':
                        $xmlReader->read();
                        if ($xmlReader->nodeType == \XMLReader::TEXT) {
                            $result['HostId'] = $xmlReader->value;
                        }
                        break;
                }
            }
        }

        return $result;
    }
1043927
protected function extract(StreamReader $reader)
    {
        $cycles = -1;
        $bytesPerCycle = 100;

        $reader->reset(null, $bytesPerCycle);

        while (
            ($trailerPos = \strpos($reader->getBuffer(false), 'trailer', \max($bytesPerCycle * $cycles++, 0))) === false
        ) {
            if ($reader->increaseLength($bytesPerCycle) === false) {
                break;
            }
        }

        if ($trailerPos === false) {
            throw new CrossReferenceException(
                'Unexpected end of cross reference. "trailer"-keyword not found.',
                CrossReferenceException::NO_TRAILER_FOUND
            );
        }

        $xrefContent = \substr($reader->getBuffer(false), 0, $trailerPos);
        $reader->reset($reader->getPosition() + $trailerPos);

        return $xrefContent;
    }
133629
public function parse(TokenStream $stream)
    {
        if ($stream->match(Token::OPERATOR, array('!', '-'))) {
            $value = $stream->current()->value;
            $stream->next();
            $ret = new Op\Unary($value, $this->parse($stream));
        } elseif ($stream->match(Token::KEYWORD, array('true', 'false'))) {
            $ret = new Node\Expr\Literal($stream->current()->value === 'true');
            $stream->next();
        } elseif ($stream->match(Token::KEYWORD, 'null')) {
            $ret = new Node\Expr\Literal(null);
            $stream->next();
        } elseif ($stream->match(Token::IDENTIFIER)) {
            $name = $stream->current()->value;
            $stream->next();

            $ret = new Node\Expr\Variable($name);
        } elseif ($stream->match(Token::STRING)) {
            $ret = new Node\Expr\Str($stream->current()->value);
            $stream->next();
        } elseif ($stream->match(Token::NUMBER)) {
            $value = $stream->current()->value;
            if (strpos('.', $value) !== false) {
                $ret = new Node\Expr\Number((float)$value);
            } else {
                $ret = new Node\Expr\Number((int)$value);
            }
            $stream->next();
        } elseif ($stream->match(Token::OPERATOR, '(')) {
            $stream->next();
            $ret = new Node\Expr\Parens($this->parse($stream));
            $stream->expect(Token::OPERATOR, ')');
        } elseif ($stream->match(Token::OPERATOR, '[')) {
            $stream->next();
            $ret = new Node\Expr\ListNode();
            if (!$stream->match(Token::OPERATOR, ']')) {
                $ret->append($this->parse($stream));
                while ($stream->match(',')) {
                    $stream->next();
                    $ret->append($this->parse($stream));
                }
            }
            $stream->expect(Token::OPERATOR, ']');
        } else {
            $this->err($stream);
            return null;
        }

        if ($stream->valid()) {
            while ($stream->valid() && $stream->match(Token::OPERATOR, array('(', '.', '['))) {
                $type = $stream->current();

                $stream->next();
                if ($type->value === '(') {
                    $ret = new Node\Expr\Call($ret);
                    if (!$stream->match(Token::OPERATOR, ')')) {
                        do {
                            $arg = $this->parse($stream);
                            $ret->append($arg);

                            if ($stream->match(',')) {
                                $stream->next();
                            } else {
                                break;
                            }
                        } while (true);
                    }
                    $stream->expect(Token::OPERATOR, ')');
                } else {
                    $ret = new Node\Expr\Subscript($ret);

                    if ($type->value === '.') {
                        $token = $stream->expect(Token::IDENTIFIER);
                        $ret->append(new Node\Expr\Str($token->value));
                    } else {
                        $ret->append($this->parse($stream));
                    }

                    switch ($type->value) {
                        case '[':
                            $stream->expect(Token::OPERATOR, ']');
                            break;
                    }
                }
            }
        }

        if ($stream->valid()) {
            if ($stream->match(Token::OPERATOR, self::$INFIX_BINARY) || $stream->match(Token::KEYWORD, 'in')) {
                $value = $stream->current()->value;
                $stream->next();
                $ret = new Op\Binary($value, $ret, $this->parse($stream));
            } elseif ($stream->match(Token::OPERATOR, '?')) {
                $stream->next();
                if ($stream->match(Token::OPERATOR, ':')) {
                    $then = null;
                } else {
                    $then = $this->parse($stream);
                }

                if ($stream->valid() && $stream->match(Token::OPERATOR, ':')) {
                    $stream->next();
                    $else = $this->parse($stream);
                } else {
                    $else = null;
                }
                $ret = new Op\Ternary('?', $ret, $then, $else);
            }
        }

        // little syntactic sugar for function calls without parentheses:
        $allowInlineCallTokens = array(Token::IDENTIFIER, Token::STRING, Token::NUMBER);
        if ($stream->valid() && ($stream->match($allowInlineCallTokens))) {
            $ret = new Node\Expr\Call($ret);
            $ret->append($this->parse($stream));
        }

        return $ret;
    }
755989
public function parse($text) {
        parent::parse($text);

        $number = self::executeStep1($this->text, $this->barcodeIdentifier, $this->serviceTypeIdentifier, $this->mailerIdentifier, $this->serialNumber);
        $crc = self::executeStep2($number);
        $codewords = self::executeStep3($number);
        $codewords = self::executeStep4($codewords, $crc);
        $characters = self::executeStep5($codewords, $crc);
        $this->data = self::executeStep6($characters);
    }
657625
public function readNextToken()
    {
        if (TokenType::EOF === $this->getTokenType())
        {
            throw new TokenizerException("Cannot read past the end of the stream.", $this->line, $this->linePos, $this->input);
        }

        // GET CURRENT; THEN MOVE POINTER
        $this->tokenValue = $c = $this->nextChar();

        if(null === $c)
        {
            $this->tokenType = TokenType::EOF;
        }

        // SPACE CHARACTER?
        elseif(ctype_space($c))
        {
            // IS LINEBREAK
            if(in_array($c, array("\r", "\n")))
            {
                $this->tokenType = TokenType::LINEBREAK;

                // IS "\r\n"?
                if("\r" === $c && "\n" === $this->currentChar())
                {
                    $this->tokenValue .= "\n";

                    $this->nextChar();
                }

                $this->line ++;

                $this->linePos = 0;
            }

            // IS OTHER CTRL CHAR, LET'S ASSUME IT IS WHITESPACE
            else
            {
                $this->tokenType = TokenType::WHITESPACE;

                while(null !== ($n = $this->currentChar()) && ctype_space($n) && ! in_array($n, array("\r", "\n")))
                {
                    $this->tokenValue .= $n;

                    $this->nextChar();
                }
            }

            // SKIP DA WHITESPACE
            if($this->skipWhitespace)
            {
                $this->readNextToken();
            }
        }
        elseif(in_array($c, array('+', '-')))
        {
            $this->tokenType = TokenType::SIGN;
        }

        // NUMBER, COULD BE
        // INT,
        // RATIONAL NUMNER (DECIMAL, CURRENCY)
        // DATE LITERAL
        // DATE TIME LITERAL
        // SIGNED NUMBER (+/-)
        elseif(ctype_digit($c))
        {
            // ASSERT: NUMBER
            $this->tokenType = TokenType::NUMBER;

            while(null !== ($n = $this->currentChar()) && ! ctype_space($n) && ! in_array($n, self::$rightDelimiters))
            {
                $this->nextChar();

                if( ! ctype_digit($n) && ! in_array($n, array(
                    '.', '-', 'T', 'Z', ':', '+'
                ))) {
                    throw new TokenizerException('Unexpected char "' . $n . '"', $this->line, $this->linePos, $this->input);
                }

                if('-' === $n && $this->tokenType !== TokenType::DATETIME_LITERAL)
                {
                    $this->tokenType = TokenType::DATE_LITERAL;
                }

                if('T' === $n)
                {
                    $this->tokenType = TokenType::DATETIME_LITERAL;
                }

                // PUSH TOKEN CHAR
                $this->tokenValue .= $n;

                // CHECK FOR COLON (INCLUDED IN DELIMITERS, SO ADVANCE IF GOT AND IS TIMESTAMP
                if(':' === $this->currentChar() && $this->tokenType === TokenType::DATETIME_LITERAL)
                {
                    $this->tokenValue .= $this->currentChar();

                    $this->nextChar();
                }
            }

            // VALIDATE DATE/DATETIME LITERALS
            if(TokenType::DATE_LITERAL === $this->getTokenType() && false === ($this->tokenValue = \DateTime::createFromFormat('Y-m-d', $this->getTokenValue())))
            {
                throw new TokenizerException('Unexpected literal format "' . $this->getTokenValue() . '"', $this->line, $this->linePos, $this->input);
            }

            // VALIDATE DATE/DATETIME LITERALS
            if(TokenType::DATETIME_LITERAL === $this->getTokenType() && false === ($this->tokenValue = \DateTime::createFromFormat(\DateTime::W3C, $this->getTokenValue())))
            {
                throw new TokenizerException('Unexpected literal format "' . $this->getTokenValue() . '"', $this->line, $this->linePos, $this->input);
            }
        }

        // STRING LITERALS
        elseif(in_array($c, array('\'', '"')))
        {
            $closed = false;

            $this->tokenType = TokenType::STRING_LITERAL;

            while(null !== ($n = $this->currentChar()))
            {
                $this->nextChar();

                $n2 = $this->currentChar();

                if('\\' === $n)
                {
                    // CHECK ALLOWED ESCAPE SEQUENCES
                    if(in_array($n2, array('n', 'M', 'r', 'R', 't', 'T', 'b', 'B', 'f', 'F', $c, '\\', '_', '%')))
                    {
                        $this->tokenValue .= '\\' . $n2;

                        continue;
                    }
                    else
                    {
                        throw new TokenizerException(sprintf('Unrecognized escape sequence "%s"', '\\' . $n2), $this->line, $this->linePos, $this->input);
                    }
                }
                else
                {
                    $this->tokenValue .= $n;

                    if($c === $n2)
                    {
                        $closed = true;

                        $this->tokenValue .= $n2;

                        $this->nextChar();

                        break;
                    }
                }
            }

            if( ! $closed)
            {
                throw new TokenizerException('Unterminated string literal', $this->line, $this->linePos, $this->input);
            }
        }

        // ARBITRARY CHAR (paranthesis, comma separator, ...)
        elseif(isset(self::$charMap[$c]))
        {
            $this->tokenType = self::$charMap[$c];
        }

        // (MATH.) [COMPOUNT] COMPARISON OPERATORS
        elseif(in_array($c, array('<', '>', '=', '!')))
        {
            $n = $this->currentChar();

            switch($c)
            {
                case '!':
                    if($n !== '=')
                    {
                        throw new TokenizerException('Unexpected "'.$n.'"', $this->line, $this->linePos, $this->input);
                    }
                    $this->tokenValue = '!=';

                    $this->tokenType = TokenType::OP_NE;

                    $this->nextChar();

                    break;

                case '<':
                    if('=' === $n)
                    {
                        $this->tokenValue = '<=';

                        $this->tokenType = TokenType::OP_LTE;

                        $this->nextChar();
                    }
                    else
                    {
                        $this->tokenType = TokenType::OP_LT;
                    }
                    break;

                case '>':
                    if('=' === $n)
                    {
                        $this->tokenValue = '>=';

                        $this->tokenType = TokenType::OP_GTE;

                        $this->nextChar();
                    }
                    else
                    {
                        $this->tokenType = TokenType::OP_GT;
                    }
                    break;

                case '=':
                    $this->tokenType = TokenType::OP_EQ;

                    break;
            }
        }

        // KEYWORDS;
        // - DATE LITERALS ("NEXT_N_YEARS:231"),
        // - ARBRITRARY EXPRESSIONS
        //   - LOGICAL OPERATORS
        //   - COMPARISON OPERATORS
        //   - FIELDNAMES
        //   - SOQL-KEYWORDS ("SELECT")
        else
        {
            // "DYNAMIC" EXPRESSIONS, CURRENTLY ONLY SUPPORTED BY DATE LITERALS
            // EXAMPLE: WHERE dateColumn < LAST_N_MONTHS:3
            $is_dynamic = false;

            $p1 = $c;

            $p2 = '';

            while(null !== ($n = $this->currentChar()) && ! ctype_space($n) && ! in_array($n, self::$rightDelimiters))
            {
                $this->nextChar();

                if( ! $is_dynamic)
                {
                    $p1 .= $n;
                }

                else
                {
                    $p2 .= $n;
                }

                $this->tokenValue .= $n;

                if(':' === $n)
                {
                    if($is_dynamic)
                    {
                        throw new TokenizerException('Unexpected ":"', $this->line, $this->linePos, $this->input);
                    }
                    $is_dynamic = true;
                }
            }

            if($is_dynamic && ! $p2)
            {
                throw new TokenizerException('Unexpected ":"', $this->line, $this->linePos, $this->input);
            }

            $t = strtoupper($p1);

            // SOQL KEYWORDS
            if(in_array($t, self::$keywords))
            {
                $this->tokenType = TokenType::KEYWORD;
            }

            else
            {
                $this->tokenType = TokenType::EXPRESSION;
            }
        }
    }
681245
public function import_from_reader(FileReader $reader)
    {
        $endian_string = $this->get_byteorder($reader->readint32());
        if (false === $endian_string) {
            return false;
        }
        $reader->setEndian($endian_string);

        $endian = ('big' == $endian_string) ? 'N' : 'V';

        $header = $reader->read(24);
        if ($reader->strlen($header) != 24) {
            return false;
        }

        // parse header
        $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header);
        if (!is_array($header)) {
            return false;
        }

        // support revision 0 of MO format specs, only
        if ($header['revision'] != 0) {
            return false;
        }

        // seek to data blocks
        $reader->seekto($header['originals_lenghts_addr']);

        // read originals' indices
        $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr'];
        if ($originals_lengths_length != $header['total'] * 8) {
            return false;
        }

        $originals = $reader->read($originals_lengths_length);
        if ($reader->strlen($originals) != $originals_lengths_length) {
            return false;
        }

        // read translations' indices
        $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr'];
        if ($translations_lenghts_length != $header['total'] * 8) {
            return false;
        }

        $translations = $reader->read($translations_lenghts_length);
        if ($reader->strlen($translations) != $translations_lenghts_length) {
            return false;
        }

        // transform raw data into set of indices
        $originals = $reader->str_split($originals, 8);
        $translations = $reader->str_split($translations, 8);

        // skip hash table
        $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4;

        $reader->seekto($strings_addr);

        $strings = $reader->read_all();
        $reader->close();

        for ($i = 0; $i < $header['total']; $i++) {
            $o = unpack("{$endian}length/{$endian}pos", $originals[$i]);
            $t = unpack("{$endian}length/{$endian}pos", $translations[$i]);
            if (!$o || !$t) {
                return false;
            }

            // adjust offset due to reading strings to separate space before
            $o['pos'] -= $strings_addr;
            $t['pos'] -= $strings_addr;

            $original = $reader->substr($strings, $o['pos'], $o['length']);
            $translation = $reader->substr($strings, $t['pos'], $t['length']);

            if ('' === $original) {
                $this->set_headers($this->make_headers($translation));
            } else {
                $entry = &static::make_entry($original, $translation);
                $this->entries[$entry->key()] = &$entry;
            }
        }

        return true;
    }
816789
public function parseString($str) {
        if (!extension_loaded("SimpleXML"))
            throw new XmlParserException("SimpleXML extension not loaded, can not parse XML");
        
        libxml_use_internal_errors(true);
        $xml = simplexml_load_string($str);
        
        if ($xml === false) {
            $msg = "The following XML errors occurred while parsing:";
            foreach (libxml_get_errors() as $error)
                $msg .= "\n" . $error->message;
            throw new XmlParserException($msg);
        }

        $this->xml = $xml;
        $this->xmlString = $str;
        return $this;
    }
98298
private function parseByteArray()
    {
        list(, $length) = unpack('N', $this->buffer);

        try {
            return substr($this->buffer, 4, $length);
        } finally {
            $this->buffer = substr($this->buffer, $length + 4);
        }
    }
262105
protected function parseDimensionsElement(\XMLReader $reader)
    {
        $dimensions = [];
        $currentDimension = null;

        while ($reader->read()) {
            switch ($reader->nodeType) {
                case \XMLReader::ELEMENT:
                    $currentDimension = $reader->name;
                    break;
                case \XMLReader::END_ELEMENT:
                    if ($reader->name === 'dimensions') {
                        return $dimensions;
                    }
                    break;
                case \XMLReader::CDATA:
                case \XMLReader::TEXT:
                    $dimensions[$currentDimension][] = $reader->value;
                    break;
            }
        }

        return $dimensions;
    }
531343
private function parseValue(Stream $stream)
    {
        if ($stream->current()->is(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)) {
            return new ValueNode($stream->expects(Token::TYPE_STRING | Token::TYPE_SINGLE_QUOTED)->getValue());
        }

        if ($stream->current()->is(Token::TYPE_NUMBER)) {
            $number = $stream->expects(Token::TYPE_NUMBER)->getValue();

            return new ValueNode(strpos($number, '.') === false ? intval($number) : floatval($number));
        }

        if ($stream->current()->is(Token::TYPE_CONSTANT)) {
            $constant = $stream->expects(Token::TYPE_CONSTANT)->getValue();

            switch ($constant) {
                case 'true':
                    return new ValueNode(true);

                case 'false':
                    return new ValueNode(false);

                case 'null':
                    return new ValueNode(null);

                default:
                    throw new ParserException(sprintf('Unexpected constant "%s" found', $constant));
            }
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '[')) {
            $stream->expects(Token::TYPE_SYMBOL, '[');

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, ']')) {
                $array = $this->parseList($stream);
            } else {
                $array = [];
            }

            $stream->expects(Token::TYPE_SYMBOL, ']');

            return new ValueNode($array);
        }

        if ($stream->current()->equals(Token::TYPE_SYMBOL, '{')) {
            $stream->expects(Token::TYPE_SYMBOL, '{');

            if (!$stream->current()->equals(Token::TYPE_SYMBOL, '}')) {
                $hash = $this->parseHashList($stream);
            } else {
                $hash = [];
            }

            $stream->expects(Token::TYPE_SYMBOL, '}');

            return new ValueNode($hash);
        }

        if ($stream->current()->equals(Token::TYPE_KEYWORD, 'new')) {
            return $this->parseClass($stream);
        }

        throw new ParserException(sprintf('Can\'t parse the stream "%s".', $stream->humanize()));
    }
190848
public static XElement parseXML(XMLStreamReader in) throws XMLStreamException {
        XElement root = parseXMLFragment(in);
        in.close();
        return root;
    }