protected function readUntilSequence($sequence) {
        $buffer = '';

        // Optimization for reading larger blocks faster.
        $first = substr($sequence, 0, 1);
        while ($this->scanner->current() !== false) {
            $buffer .= $this->scanner->charsUntil($first);

            // Stop as soon as we hit the stopping condition.
            if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) {
                return $buffer;
            }
            $buffer .= $this->scanner->current();
            $this->scanner->next();
        }

        // If we get here, we hit the EOF.
        $this->parseError("Unexpected EOF during text read.");
        return $buffer;
    }