Compress the lexer into value string until current lookahead

@access public
@return string the compressed value string
327887
public function compress()
    {
        $current   = $this->lexer->lookahead['position'];
        $this->lexer->reset();
        $string = '';
        
        while($this->lexer->moveNext() && $this->lexer->lookahead['position'] <= $current) {
            $string .= $this->lexer->lookahead['value'];
        }
        
        return $string;
    }
1165993
public function readString()
    {
        $strlen = $this->readVInt();
        if ($strlen == 0) {
            return '';
        } else {
            /**
             * This implementation supports only Basic Multilingual Plane
             * (BMP) characters (from 0x0000 to 0xFFFF) and doesn't support
             * "supplementary characters" (characters whose code points are
             * greater than 0xFFFF)
             * Java 2 represents these characters as a pair of char (16-bit)
             * values, the first from the high-surrogates range (0xD800-0xDBFF),
             * the second from the low-surrogates range (0xDC00-0xDFFF). Then
             * they are encoded as usual UTF-8 characters in six bytes.
             * Standard UTF-8 representation uses four bytes for supplementary
             * characters.
             */

            $str_val = $this->_fread($strlen);

            for ($count = 0; $count < $strlen; $count++ ) {
                if (( ord($str_val[$count]) & 0xC0 ) == 0xC0) {
                    $addBytes = 1;
                    if (ord($str_val[$count]) & 0x20 ) {
                        $addBytes++;

                        // Never used. Java2 doesn't encode strings in four bytes
                        if (ord($str_val[$count]) & 0x10 ) {
                            $addBytes++;
                        }
                    }
                    $str_val .= $this->_fread($addBytes);
                    $strlen += $addBytes;

                    // Check for null character. Java2 encodes null character
                    // in two bytes.
                    if (ord($str_val[$count])   == 0xC0 
                        && ord($str_val[$count+1]) == 0x80   
                    ) {
                        $str_val[$count] = 0;
                        $str_val = substr($str_val, 0, $count+1)
                                 . substr($str_val, $count+2);
                    }
                    $count += $addBytes;
                }
            }

            return $str_val;
        }
    }
297729
public function performReadonlyTransformation()
    {
        $values = '';
        $data   = [];

        $items = $this->value;
        if ($this->source) {
            foreach ($this->source as $source) {
                if (is_object($source)) {
                    $sourceTitles[$source->ID] = $source->Title;
                }
            }
        }

        if ($items) {
            // Items is a DO Set
            if (is_a($items, 'DataList')) {
                foreach ($items as $item) {
                    $data[] = $item->Title;
                }
                if ($data) $values = implode(', ', $data);

                // Items is an array or single piece of string (including comma seperated string)
            } else {
                if (!is_array($items)) {
                    $items = preg_split('/ *, */', trim($items));
                }

                foreach ($items as $item) {
                    if (is_array($item)) {
                        $data[] = $item['Title'];
                    } elseif (is_array($this->source) && !empty($this->source[$item])) {
                        $data[] = $this->source[$item];
                    } elseif (is_a($this->source, 'DataList')) {
                        $data[] = $sourceTitles[$item];
                    } else {
                        $data[] = $item;
                    }
                }

                $values = implode(', ', $data);
            }
        }

        $title = ($this->title) ? $this->title : '';

        $field = new ReadonlyField($this->name, $title, $values);
        $field->setForm($this->form);

        return $field;
    }
216458
public function StringPrimary()
    {
        $lookaheadType = $this->lexer->lookahead['type'];

        switch ($lookaheadType) {
            case Lexer::T_IDENTIFIER:
                $peek = $this->lexer->glimpse();

                if ($peek['value'] == '.') {
                    return $this->StateFieldPathExpression();
                }

                if ($peek['value'] == '(') {
                    // do NOT directly go to FunctionsReturningString() because it doesn't check for custom functions.
                    return $this->FunctionDeclaration();
                }

                $this->syntaxError("'.' or '('");
                break;

            case Lexer::T_STRING:
                $this->match(Lexer::T_STRING);

                return new AST\Literal(AST\Literal::STRING, $this->lexer->token['value']);

            case Lexer::T_INPUT_PARAMETER:
                return $this->InputParameter();

            case Lexer::T_CASE:
            case Lexer::T_COALESCE:
            case Lexer::T_NULLIF:
                return $this->CaseExpression();

            default:
                if ($this->isAggregateFunction($lookaheadType)) {
                    return $this->AggregateExpression();
                }
        }

        $this->syntaxError(
            'StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression'
        );
    }
1162383
public function ScalarExpression()
    {
        $lookahead = $this->lexer->lookahead['type'];
        $peek      = $this->lexer->glimpse();

        switch (true) {
            case ($lookahead === Lexer::T_INTEGER):
            case ($lookahead === Lexer::T_FLOAT):
            // SimpleArithmeticExpression : (- u.value ) or ( + u.value )  or ( - 1 ) or ( + 1 )
            case ($lookahead === Lexer::T_MINUS):
            case ($lookahead === Lexer::T_PLUS):
                return $this->SimpleArithmeticExpression();

            case ($lookahead === Lexer::T_STRING):
                return $this->StringPrimary();

            case ($lookahead === Lexer::T_TRUE):
            case ($lookahead === Lexer::T_FALSE):
                $this->match($lookahead);

                return new AST\Literal(AST\Literal::BOOLEAN, $this->lexer->token['value']);

            case ($lookahead === Lexer::T_INPUT_PARAMETER):
                switch (true) {
                     case $this->isMathOperator($peek):
                        // :param + u.value
                        return $this->SimpleArithmeticExpression();

                    default:
                        return $this->InputParameter();
                }

            case ($lookahead === Lexer::T_CASE):
            case ($lookahead === Lexer::T_COALESCE):
            case ($lookahead === Lexer::T_NULLIF):
                // Since NULLIF and COALESCE can be identified as a function,
                // we need to check these before checking for FunctionDeclaration
                return $this->CaseExpression();

            case ($lookahead === Lexer::T_OPEN_PARENTHESIS):
                return $this->SimpleArithmeticExpression();

            // this check must be done before checking for a filed path expression
            case ($this->isFunction()):
                $this->lexer->peek(); // "("

                switch (true) {
                    case ($this->isMathOperator($this->peekBeyondClosingParenthesis())):
                        // SUM(u.id) + COUNT(u.id)
                        return $this->SimpleArithmeticExpression();

                    case ($this->isAggregateFunction($this->lexer->lookahead['type'])):
                        return $this->AggregateExpression();

                    default:
                        // IDENTITY(u)
                        return $this->FunctionDeclaration();
                }

                break;
            // it is no function, so it must be a field path
            case ($lookahead === Lexer::T_IDENTIFIER):
                $this->lexer->peek(); // lookahead => '.'
                $this->lexer->peek(); // lookahead => token after '.'
                $peek = $this->lexer->peek(); // lookahead => token after the token after the '.'
                $this->lexer->resetPeek();

                if ($this->isMathOperator($peek)) {
                    return $this->SimpleArithmeticExpression();
                }

                return $this->StateFieldPathExpression();

            default:
                $this->syntaxError();
        }
    }
1079173
public function compress(): array
    {
        $hs = [];
        foreach ($this->headers as $k => $header) {
            $vs = $header->getValues();
            $v = trim(implode(',', $vs));
            $hs[] = trim("$k: $v");
        }
        return $hs;
    }
184308
private function Values()
	{
		$values = [$this->Value()];

		while ( $this->lexer->isNextToken( DocLexer::T_COMMA ) )
		{
			$this->match( DocLexer::T_COMMA );

			if ( $this->lexer->isNextToken( DocLexer::T_CLOSE_PARENTHESIS ) )
				break;

			$token = $this->lexer->lookahead;
			$value = $this->Value();

			if ( !is_object( $value ) && !is_array( $value ) )
				$this->syntaxError( 'Value', $token );

			$values[] = $value;
		}

		foreach ( $values as $k => $value )
		{
			if ( is_object( $value ) && $value instanceof \stdClass )
				$values[$value->name] = $value->value;
			else if ( !isset( $values['value'] ) )
				$values['value'] = $value;
			else
			{
				if ( !is_array( $values['value'] ) )
					$values['value'] = [$values['value']];

				$values['value'][] = $value;
			}

			unset( $values[$k] );
		}

		return $values;
	}
605050
public function toLowerCaseFirst() {
		$first = $this->substring(0, 1);
		$rest = $this->substring(1);

		return new Text(mb_strtolower($first, $this->encoding) . $rest, $this->encoding);
	}
792135
protected function saveRegex()
	{
		echo $this->a . $this->b;

		while (($this->a = $this->getChar()) !== false)
		{
			if ($this->a === '/')
			{
				break;
			}

			if ($this->a === '\\')
			{
				echo $this->a;
				$this->a = $this->getChar();
			}

			if ($this->a === "\n")
			{
				throw new \RuntimeException('Unclosed regex pattern at position: ' . $this->index);
			}

			echo $this->a;
		}

		$this->b = $this->getReal();
	}
1033522
public function encoded()
    {
        $encoded = collect();

        $this->each(function ($model) use (&$encoded) {
            $pool = Mention::pool($model);
            $encoded->push("{$pool->key}:{$model->getKey()}");
        });

        return $encoded->implode(',');
    }
877979
public function toSixFigureString()
	{
		$hundredkmE = floor($this->easting / 100000);
		$hundredkmN = floor($this->northing / 100000);

		if ($hundredkmN < 5) {
			$firstLetter = ($hundredkmE < 5) ? 'S' : 'T';
		} else if ($hundredkmN < 10) {
			$firstLetter = ($hundredkmE < 5) ? 'N' : 'O';
		} else {
			$firstLetter = 'H';
		}

		$index = 65 + ((4 - ($hundredkmN % 5)) * 5) + ($hundredkmE % 5);
		$ti = $index;
		if ($index >= 73) {
			$index++;
		}

		$secondLetter = chr($index);

		$e = round(($this->easting - (100000 * $hundredkmE)) / 100);
		$n = round(($this->northing - (100000 * $hundredkmN)) / 100);

		return sprintf('%s%s%03d%03d', $firstLetter, $secondLetter, $e, $n);
	}
301670
public function toString()
    {
        $parts = [];

        if ($this->operand) {
            $parts[] = (string)$this->operand;
        }

        if ($this->constraint) {
            $parts[] = (string)$this->constraint;
        }

        return implode(' ', $parts);
    }
1014876
public function getContent() {

        $size = $this->getSize();

        if($size > 0) {

            $pos = $this->ftell();

            $this->fseek(0);
            $return = $this->fread($size);
            $this->fseek($pos);

            return $return;
        }

        return '';
    }
1163236
protected function decodeHeader()
    {
        if (isset($this->header->subject)) {
            $this->header->subject = $this->mimeHeaderDecode($this->header->subject);
        }
        if (isset($this->header->details->subject)) {
            $this->header->details->subject = $this->mimeHeaderDecode($this->header->details->subject);
        }
        if (isset($this->header->details->Subject)) {
            $this->header->details->Subject = $this->mimeHeaderDecode($this->header->details->Subject);
        }
        if (isset($this->header->from)) {
            $this->header->from = $this->mimeHeaderDecode($this->header->from);
        }
        if (isset($this->header->to)) {
            $this->header->to = $this->mimeHeaderDecode($this->header->to);
        }
    }
751753
private function convertEncoding()
    {
        $convert = new EncodingHandler($this->content, $this->encoding);
        if (($result = $convert->auto()) !== false) {
            $this->encoding = self::ENCODING;
            mb_internal_encoding(self::ENCODING);
            return $this->content = $result;
        }
        mb_internal_encoding(self::ENCODING);
        return $this->content;
    }
755719
public function ToString()
	{
		$result = "";
		$format = "H:i:s";

		if ( ! @empty( $this->Value->microseconds != 0 ) )
		{
			$format .= "." . rtrim( $this->Value->microseconds, "0" );
		}

		if ( ! $this->IsLocal )
		{
			$format .= $this->Value->getOffset() == 0
	   		 	? "\Z"
	   			: "P";
		}

		return $this->Value->format( $format );
	}
920944
public function SimpleConditionalExpression()
    {
        if ($this->lexer->isNextToken(Lexer::T_EXISTS)) {
            return $this->ExistsExpression();
        }

        $token     = $this->lexer->lookahead;
        $peek      = $this->lexer->glimpse();
        $lookahead = $token;

        if ($this->lexer->isNextToken(Lexer::T_NOT)) {
            $token = $this->lexer->glimpse();
        }

        if ($token['type'] === Lexer::T_IDENTIFIER || $token['type'] === Lexer::T_INPUT_PARAMETER || $this->isFunction()) {
            // Peek beyond the matching closing parenthesis.
            $beyond = $this->lexer->peek();

            switch ($peek['value']) {
                case '(':
                    // Peeks beyond the matched closing parenthesis.
                    $token = $this->peekBeyondClosingParenthesis(false);

                    if ($token['type'] === Lexer::T_NOT) {
                        $token = $this->lexer->peek();
                    }

                    if ($token['type'] === Lexer::T_IS) {
                        $lookahead = $this->lexer->peek();
                    }
                    break;

                default:
                    // Peek beyond the PathExpression or InputParameter.
                    $token = $beyond;

                    while ($token['value'] === '.') {
                        $this->lexer->peek();

                        $token = $this->lexer->peek();
                    }

                    // Also peek beyond a NOT if there is one.
                    if ($token['type'] === Lexer::T_NOT) {
                        $token = $this->lexer->peek();
                    }

                    // We need to go even further in case of IS (differentiate between NULL and EMPTY)
                    $lookahead = $this->lexer->peek();
            }

            // Also peek beyond a NOT if there is one.
            if ($lookahead['type'] === Lexer::T_NOT) {
                $lookahead = $this->lexer->peek();
            }

            $this->lexer->resetPeek();
        }

        if ($token['type'] === Lexer::T_BETWEEN) {
            return $this->BetweenExpression();
        }

        if ($token['type'] === Lexer::T_LIKE) {
            return $this->LikeExpression();
        }

        if ($token['type'] === Lexer::T_IN) {
            return $this->InExpression();
        }

        if ($token['type'] === Lexer::T_INSTANCE) {
            return $this->InstanceOfExpression();
        }

        if ($token['type'] === Lexer::T_MEMBER) {
            return $this->CollectionMemberExpression();
        }

        if ($token['type'] === Lexer::T_IS && $lookahead['type'] === Lexer::T_NULL) {
            return $this->NullComparisonExpression();
        }

        if ($token['type'] === Lexer::T_IS && $lookahead['type'] === Lexer::T_EMPTY) {
            return $this->EmptyCollectionComparisonExpression();
        }

        return $this->ComparisonExpression();
    }