public function readString(array $escapeSequences = null, $raw = false)
    {
        if (!$this->peekQuote()) {
            return;
        }

        $quoteStyle = $this->consume();

        $char = null;
        $string = '';
        $closed = false;
        while ($this->hasLength()) {
            $char = $this->peek();
            $this->consume();

            //Handle escaping based on passed sequences
            if ($char === '\\') {
                $nextChar = $this->consume(1);
                $string .= array_key_exists($nextChar, $escapeSequences ?: [])
                    //Peek the escape sequence
                    ? $escapeSequences[$nextChar]
                    //Peek the next char
                    : ($raw ? $char : '').$nextChar;
                continue;
            }

            //End the string (Escaped quotes have already been handled)
            if ($char === $quoteStyle) {
                $closed = true;

                break;
            }

            $string .= $char;
        }

        if (!$closed) {
            $this->throwException(
                "Unclosed string ($quoteStyle) encountered"
            );
        }

        if ($raw) {
            $string = $quoteStyle.$string.$quoteStyle;
        }

        return $string;
    }
public function readString(array $escapeSequences = null, $raw = false)
    {
        if (!$this->peekQuote()) {
            return;
        }

        $quoteStyle = $this->consume();

        $char = null;
        $string = '';
        $closed = false;
        while ($this->hasLength()) {
            $char = $this->peek();
            $this->consume();

            //Handle escaping based on passed sequences
            if ($char === '\\') {
                $nextChar = $this->consume(1);
                $string .= array_key_exists($nextChar, $escapeSequences ?: [])
                    //Peek the escape sequence
                    ? $escapeSequences[$nextChar]
                    //Peek the next char
                    : ($raw ? $char : '').$nextChar;
                continue;
            }

            //End the string (Escaped quotes have already been handled)
            if ($char === $quoteStyle) {
                $closed = true;

                break;
            }

            $string .= $char;
        }

        if (!$closed) {
            $this->throwException(
                "Unclosed string ($quoteStyle) encountered"
            );
        }

        if ($raw) {
            $string = $quoteStyle.$string.$quoteStyle;
        }

        return $string;
    }
public function readString ( array $ escapeSequences = null , $ raw = false ) { if ( ! $ this -> peekQuote ( ) ) { return ; } $ quoteStyle = $ this -> consume ( ) ; $ char = null ; $ string = '' ; $ closed = false ; while ( $ this -> hasLength ( ) ) { $ char = $ this -> peek ( ) ; $ this -> consume ( ) ; //Handle escaping based on passed sequences if ( $ char === '\\' ) { $ nextChar = $ this -> consume ( 1 ) ; $ string .= array_key_exists ( $ nextChar , $ escapeSequences ? : [ ] ) //Peek the escape sequence ? $ escapeSequences [ $ nextChar ] //Peek the next char : ( $ raw ? $ char : '' ) . $ nextChar ; continue ; } //End the string (Escaped quotes have already been handled) if ( $ char === $ quoteStyle ) { $ closed = true ; break ; } $ string .= $ char ; } if ( ! $ closed ) { $ this -> throwException ( "Unclosed string ($quoteStyle) encountered" ) ; } if ( $ raw ) { $ string = $ quoteStyle . $ string . $ quoteStyle ; } return $ string ; }
Reads an enclosed string correctly.

Strings start with a quote and end with that same quote while other quotes inside it
are ignored, including other kinds of expressions.

The quote itself is automatically passed as an escape sequence, so a '-enclosed string always knows \' as
an escape expression.

@param bool $raw whether to return the string raw, with quotes and keep escape sequences intact.

@return string|null the resulting string or null if none encountered.
Reads an enclosed string correctly .