Test whether current token is between two htmlspecialchars() calls

@return bool
486943
protected function isBetweenHtmlspecialcharCalls()
	{
		return ($this->tokens[$this->i + 1]    === [T_STRING, 'htmlspecialchars']
		     && $this->tokens[$this->i + 2]    === '('
		     && $this->tokens[$this->i - 1]    === ')'
		     && $this->tokens[$this->i - 2][0] === T_LNUMBER
		     && $this->tokens[$this->i - 3]    === ',');
	}
517917
function ReadChar()
    {
        if ($this->IsAtEnd())
            return false;
        
        $ch = $this->string{$this->idx};
        ++$this->idx;
        if ($ch >= $this->utf8Start && !$this->IsAtEnd())
        {
            $ch .= $this->string{$this->idx};
            ++$this->idx;
        }
        return $ch;
    }
1264703
public function detectCurrentLanguage()
    {
        // parsing url to get only path & removing prefix if there is one
        $escapedPathPrefix = Text::escapeForRegex($this->config->getPathPrefix());
        $uriPath = parse_url($this->config->getRaw(), PHP_URL_PATH);
        $uriPath = preg_replace('/^' . $escapedPathPrefix . '/s', '', $uriPath);
        $uriSegments = explode('/', $uriPath);

        if (isset($uriSegments[1]) && in_array($uriSegments[1], $this->translate->getLanguages())) {
            return $uriSegments[1];
        }
        return $this->translate->getDefault();
    }
1201649
public function isTranslable()
    {
        if ($this->getPath() === null) {
            $this->detectUrlDetails();
        }

        foreach ($this->config->getExcludedUrls() as $regex) {
            $escapedRegex = Text::escapeForRegex(Text::fullTrim($regex));
            $fullRegex = sprintf('/%s/', $escapedRegex);

            if (preg_match($fullRegex, $this->getPath()) === 1) {
                return false;
            }
        }

        return true;
    }
1282208
private function isShort()
    {
        $length = Utf8::strlen($this->word);
        return ( ($this->searchShortSyllabe(-3, 3) || $this->searchShortSyllabe(-2, 2)) && ($length == $this->r1Index) );
    }
954030
public static function checkBrowserShiretoko()
    {
        if (stripos(self::$userAgentString, 'Mozilla') !== false &&
            preg_match('/Shiretoko\/([^ ]*)/i', self::$userAgentString, $matches)
        ) {
            if (isset($matches[1])) {
                self::$browser->setVersion($matches[1]);
            }
            self::$browser->setName(Browser::SHIRETOKO);

            return true;
        }

        return false;
    }
502138
protected function isSyntacticallyValid(): bool
    {
        if (preg_match('!^([a-z][a-z0-9\+]*)://([^@]+@)?([^/?#]*)(/([^#?]*))?(.*)$!', $this->parsedUri->asString()) == 0) {
            return false;
        }

        if ($this->parsedUri->hasUser()) {
            if (preg_match('~([@:/])~', $this->parsedUri->user()) != 0) {
                return false;
            }

            if (!empty($this->parsedUri->password()) && preg_match('~([@:/])~', $this->parsedUri->password()) != 0) {
                return false;
            }
        }

        if (!$this->parsedUri->hasHostname() || strlen($this->parsedUri->hostname()) === 0) {
            return true;
        }

        if ($this->parsedUri->hasHostname()
          && preg_match('!^([a-zA-Z0-9\.-]+|\[[^\]]+\])(:([0-9]+))?$!', $this->parsedUri->hostname()) != 0) {
            return true;
        }

        return false;
    }
846786
public function isPair()
    {
        if (0 === strpos(trim($this->text), '#')) {
            return false;
        }
        
        $pieces = explode('=', $this->text, 2);
        $pieces = array_map('trim', $pieces);

        return 2 === count($pieces);
    }
66482
public function detect()
	{
		if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
		{
			$browserLangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
			$systemLangs  = $this->available();
			foreach ($browserLangs as $browserLang)
			{
				// Slice out the part before ; on first step, the part before - on second, place into array
				$browserLang = substr($browserLang, 0, strcspn($browserLang, ';'));
				$primary_browserLang = substr($browserLang, 0, 2);
				foreach ($systemLangs as $systemLang)
				{
					// Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
					$Jinstall_lang = $systemLang->lang_code;

					if (strlen($Jinstall_lang) < 6)
					{
						if (strtolower($browserLang) == strtolower(substr($systemLang->lang_code, 0, strlen($browserLang))))
						{
							return $systemLang->lang_code;
						}
						elseif ($primary_browserLang == substr($systemLang->lang_code, 0, 2))
						{
							$primaryDetectedLang = $systemLang->lang_code;
						}
					}
				}

				if (isset($primaryDetectedLang))
				{
					return $primaryDetectedLang;
				}
			}
		}

		return null;
	}
1332476
public function getNextToken()
    {
        $token = \array_pop($this->stack);
        if ($token !== null) {
            return $token;
        }

        if (($byte = $this->streamReader->readByte()) === false) {
            return false;
        }

        if ($byte === "\x20" ||
            $byte === "\x0A" ||
            $byte === "\x0D" ||
            $byte === "\x0C" ||
            $byte === "\x09" ||
            $byte === "\x00"
        ) {
            if ($this->leapWhiteSpaces() === false) {
                return false;
            }
            $byte = $this->streamReader->readByte();
        }

        switch ($byte) {
            case '/':
            case '[':
            case ']':
            case '(':
            case ')':
            case '{':
            case '}':
            case '<':
            case '>':
                return $byte;
            case '%':
                $this->streamReader->readLine();
                return $this->getNextToken();
        }

        /* This way is faster than checking single bytes.
         */
        $bufferOffset = $this->streamReader->getOffset();
        do {
            $lastBuffer = $this->streamReader->getBuffer(false);
            $pos = \strcspn(
                $lastBuffer,
                "\x00\x09\x0A\x0C\x0D\x20()<>[]{}/%",
                $bufferOffset
            );
        } while (
            // Break the loop if a delimiter or white space char is matched
            // in the current buffer or increase the buffers length
            $lastBuffer !== false &&
            (
                $bufferOffset + $pos === \strlen($lastBuffer) &&
                $this->streamReader->increaseLength()
            )
        );

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

        return $result;
    }
744953
protected function _getNextToken()
    {
        $this->_token      = self::EOF;
        $this->_tokenValue = null;
        $this->_eatWhitespace();

        if ($this->_offset >= $this->_sourceLength) {
            return(self::EOF);
        }

        $str        = $this->_source;
        $str_length = $this->_sourceLength;
        $i          = $this->_offset;
        $start      = $i;

        switch ($str{$i}) {
        case '{':
            $this->_token = self::LBRACE;
            break;
        case '}':
            $this->_token = self::RBRACE;
            break;
        case '[':
            $this->_token = self::LBRACKET;
            break;
        case ']':
            $this->_token = self::RBRACKET;
            break;
        case ',':
            $this->_token = self::COMMA;
            break;
        case ':':
            $this->_token = self::COLON;
            break;
        case  '"':
            $result = '';
            do {
                $i++;
                if ($i >= $str_length) {
                    break;
                }

                $chr = $str{$i};
                if ($chr == '\\') {
                    $i++;
                    if ($i >= $str_length) {
                        break;
                    }
                    $chr = $str{$i};
                    switch ($chr) {
                    case '"' :
                        $result .= '"';
                        break;
                    case '\\':
                        $result .= '\\';
                        break;
                    case '/' :
                        $result .= '/';
                        break;
                    case 'b' :
                        $result .= chr(8);
                        break;
                    case 'f' :
                        $result .= chr(12);
                        break;
                    case 'n' :
                        $result .= chr(10);
                        break;
                    case 'r' :
                        $result .= chr(13);
                        break;
                    case 't' :
                        $result .= chr(9);
                        break;
                    case '\'' :
                        $result .= '\'';
                        break;
                    default:
                        throw new Zend_Json_Exception(
                            "Illegal escape "
                                .  "sequence '" . $chr . "'"
                        );
                    }
                } elseif ($chr == '"') {
                    break;
                } else {
                    $result .= $chr;
                }
            } while ($i < $str_length);

            $this->_token = self::DATUM;
            //$this->_tokenValue = substr($str, $start + 1, $i - $start - 1);
            $this->_tokenValue = $result;
            break;
        case 't':
            if (($i+ 3) < $str_length && substr($str, $start, 4) == "true") {
                $this->_token = self::DATUM;
            }
            $this->_tokenValue = true;
            $i += 3;
            break;
        case 'f':
            if (($i+ 4) < $str_length && substr($str, $start, 5) == "false") {
                $this->_token = self::DATUM;
            }
            $this->_tokenValue = false;
            $i += 4;
            break;
        case 'n':
            if (($i+ 3) < $str_length && substr($str, $start, 4) == "null") {
                $this->_token = self::DATUM;
            }
            $this->_tokenValue = null;
            $i += 3;
            break;
        }

        if ($this->_token != self::EOF) {
            $this->_offset = $i + 1; // Consume the last token character
            return($this->_token);
        }

        $chr = $str{$i};
        if ($chr == '-' || $chr == '.' || ($chr >= '0' && $chr <= '9')) {
            if (preg_match(
                '/-?([0-9])*(\.[0-9]*)?((e|E)((-|\+)?)[0-9]+)?/s',
                $str, $matches, PREG_OFFSET_CAPTURE, $start
            ) && $matches[0][1] == $start
            ) {

                $datum = $matches[0][0];

                if (is_numeric($datum)) {
                    if (preg_match('/^0\d+$/', $datum)) {
                        throw new Zend_Json_Exception("Octal notation not supported by JSON (value: $datum)");
                    } else {
                        $val  = intval($datum);
                        $fVal = floatval($datum);
                        $this->_tokenValue = ($val == $fVal ? $val : $fVal);
                    }
                } else {
                    throw new Zend_Json_Exception("Illegal number format: $datum");
                }

                $this->_token = self::DATUM;
                $this->_offset = $start + strlen($datum);
            }
        } else {
            throw new Zend_Json_Exception('Illegal Token');
        }

        return($this->_token);
    }
538500
public function lex()
    {
        // TODO: Sometimes, static::parse* functions make unnecessary calls to
        // is* functions. For a better performance, some rules can be deduced
        // from context.
        // For example, in `parseBool` there is no need to compare the token
        // every time with `true` and `false`. The first step would be to
        // compare with 'true' only and just after that add another letter from
        // context and compare again with `false`.
        // Another example is `parseComment`.

        $list = new TokensList();

        /**
         * Last processed token.
         *
         * @var Token
         */
        $lastToken = null;

        for ($this->last = 0, $lastIdx = 0; $this->last < $this->len; $lastIdx = ++$this->last) {
            /**
             * The new token.
             *
             * @var Token
             */
            $token = null;

            foreach (static::$PARSER_METHODS as $method) {
                if ($token = $this->$method()) {
                    break;
                }
            }

            if ($token === null) {
                // @assert($this->last === $lastIdx);
                $token = new Token($this->str[$this->last]);
                $this->error(
                    'Unexpected character.',
                    $this->str[$this->last],
                    $this->last
                );
            } elseif ($lastToken !== null
                && $token->type === Token::TYPE_SYMBOL
                && $token->flags & Token::FLAG_SYMBOL_VARIABLE
                && (
                    $lastToken->type === Token::TYPE_STRING
                    || (
                        $lastToken->type === Token::TYPE_SYMBOL
                        && $lastToken->flags & Token::FLAG_SYMBOL_BACKTICK
                    )
                )
            ) {
                // Handles ```... FROM 'user'@'%' ...```.
                $lastToken->token .= $token->token;
                $lastToken->type = Token::TYPE_SYMBOL;
                $lastToken->flags = Token::FLAG_SYMBOL_USER;
                $lastToken->value .= '@' . $token->value;
                continue;
            } elseif ($lastToken !== null
                && $token->type === Token::TYPE_KEYWORD
                && $lastToken->type === Token::TYPE_OPERATOR
                && $lastToken->value === '.'
            ) {
                // Handles ```... tbl.FROM ...```. In this case, FROM is not
                // a reserved word.
                $token->type = Token::TYPE_NONE;
                $token->flags = 0;
                $token->value = $token->token;
            }

            $token->position = $lastIdx;

            $list->tokens[$list->count++] = $token;

            // Handling delimiters.
            if ($token->type === Token::TYPE_NONE && $token->value === 'DELIMITER') {
                if ($this->last + 1 >= $this->len) {
                    $this->error(
                        'Expected whitespace(s) before delimiter.',
                        '',
                        $this->last + 1
                    );
                    continue;
                }

                // Skipping last R (from `delimiteR`) and whitespaces between
                // the keyword `DELIMITER` and the actual delimiter.
                $pos = ++$this->last;
                if (($token = $this->parseWhitespace()) !== null) {
                    $token->position = $pos;
                    $list->tokens[$list->count++] = $token;
                }

                // Preparing the token that holds the new delimiter.
                if ($this->last + 1 >= $this->len) {
                    $this->error(
                        'Expected delimiter.',
                        '',
                        $this->last + 1
                    );
                    continue;
                }
                $pos = $this->last + 1;

                // Parsing the delimiter.
                $this->delimiter = null;
                $delimiterLen = 0;
                while (++$this->last < $this->len && ! Context::isWhitespace($this->str[$this->last]) && $delimiterLen < 15) {
                    $this->delimiter .= $this->str[$this->last];
                    ++$delimiterLen;
                }

                if (empty($this->delimiter)) {
                    $this->error(
                        'Expected delimiter.',
                        '',
                        $this->last
                    );
                    $this->delimiter = ';';
                }

                --$this->last;

                // Saving the delimiter and its token.
                $this->delimiterLen = strlen($this->delimiter);
                $token = new Token($this->delimiter, Token::TYPE_DELIMITER);
                $token->position = $pos;
                $list->tokens[$list->count++] = $token;
            }

            $lastToken = $token;
        }

        // Adding a final delimiter to mark the ending.
        $list->tokens[$list->count++] = new Token(null, Token::TYPE_DELIMITER);

        // Saving the tokens list.
        $this->list = $list;
    }
542366
protected function detectCharset(): bool
    {
        // set the default
        $encode = new Encode;
        $encode->from($this->defaultCharset);
        $encode->to($this->defaultCharset);

        if ( ! is_null($this->options->enforceEncoding)) {
            //  they want to enforce the given encoding
            $encode->from($this->options->enforceEncoding);
            $encode->to($this->options->enforceEncoding);

            return false;
        }

        $meta = $this->root->find('meta[http-equiv=Content-Type]', 0);
        if (is_null($meta)) {
            // could not find meta tag
            $this->root->propagateEncoding($encode);

            return false;
        }
        $content = $meta->content;
        if (empty($content)) {
            // could not find content
            $this->root->propagateEncoding($encode);

            return false;
        }
        $matches = [];
        if (preg_match('/charset=(.+)/', $content, $matches)) {
            $encode->from(trim($matches[1]));
            $this->root->propagateEncoding($encode);

            return true;
        }

        // no charset found
        $this->root->propagateEncoding($encode);

        return false;
    }
1115580
private function isEndToken()
    {
        return $this->tokenIs(';')
        || $this->tokenIs(',')
        || $this->tokenIs(')')
        || $this->tokenIs(']')
        || $this->tokenIs(T_DOUBLE_ARROW);
    }
828442
protected function checkBrowserInternetExplorer() 
    {
        $match = '';
        
	    // Test for v1 - v1.5 IE
	    if( stripos($this->_agent,'microsoft internet explorer') !== false ) 
	    {
		    $this->setBrowser(self::BROWSER_IE);
		    $this->setVersion('1.0');
		    $aresult = stristr($this->_agent, '/');
		    if( preg_match('/308|425|426|474|0b1/i', $aresult) ) {
			    $this->setVersion('1.5');
		    }
			return true;
	    }
	    // Test for versions > 1.5
	    else if( stripos($this->_agent,'msie')     !== false 
	          && stripos($this->_agent,'opera')    === false 
	          && stripos($this->_agent,'iemobile') === false ) 
	    {
	    	/*// See if the browser is the odd MSN Explorer
	    	if( stripos($this->_agent,'msnb') !== false ) {
		    	$aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'MSN'));
			    $this->setBrowser( self::BROWSER_MSN );
			    $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
			    return true;
	    	} */
	    	$aresult = explode(' ',stristr(str_replace(';','; ',$this->_agent),'msie'));
	    	$this->setBrowser( self::BROWSER_IE );
	    	$this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
	    	return true;
	    }
	    // Test for versions for Edge
	    else if ( stripos($this->_agent,'Edge')          !== false 
	    	   && stripos($this->_agent,'windows phone') === false ) 
	    {
	        $aresult = explode('/',stristr($this->_agent,'Edge'));
	        $aversion = explode('.',$aresult[1]);
	        $this->setVersion($aversion[0]);
	        $this->setBrowser(self::BROWSER_MS_EDGE);
	        return true;
	    }
	    // Test for versions for Edge mobile
	    else if ( stripos($this->_agent,'Edge')          !== false
	           && stripos($this->_agent,'windows phone') !== false )
	    {
	        $aresult = explode('/',stristr($this->_agent,'Edge'));
	        $aversion = explode('.',$aresult[1]);
	        $this->setVersion($aversion[0]);
	        $this->setBrowser(self::BROWSER_MS_EDGE_MOBILE);
	        $this->setPlatform( self::PLATFORM_WINDOWS_PHONE );
	        $this->setMobile(true);
	        return true;
	    }
	    
	    // Test for versions > 10
	    else if (  preg_match('/Trident\/[0-9\.]+/', $this->_agent) 
	            && preg_match('/rv:([0-9\.]+)/', $this->_agent, $match) )
	    {
	        $this->setBrowser( self::BROWSER_IE );
	        $this->setVersion($match[1]);
	        return true;
	    }
	    else if (stripos($this->_agent,'iemobile')      !== false
	          && stripos($this->_agent,'windows phone') !== false ) 
	    { // Windows Phones mit IEMobile
	        $this->setPlatform( self::PLATFORM_WINDOWS_PHONE );
	        $this->setBrowser( self::BROWSER_IE_MOBILE );
	        $this->setMobile(true);
	        $aresult = explode(' ',stristr(str_replace('/',' ',$this->_agent),'iemobile'));
	        $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
	        return true;
	    }
	    else if (stripos($this->_agent,'iemobile')      !== false
	          && stripos($this->_agent,'windows phone') === false )
	    { // Irgendwas mit IEMobile
    	    $this->setBrowser( self::BROWSER_IE_MOBILE );
    	    $this->setMobile(true);
    	    $aresult = explode(' ',stristr(str_replace('/',' ',$this->_agent),'iemobile'));
    	    $this->setVersion(str_replace(array('(',')',';'),'',$aresult[1]));
    	    return true;
	    }
	    // Test for Pocket IE
	    else if( stripos($this->_agent,'mspie') !== false || stripos($this->_agent,'pocket') !== false ) 
	    {
		    $aresult = explode(' ',stristr($this->_agent,'mspie'));
		    $this->setPlatform( self::PLATFORM_WINDOWS_CE );
		    $this->setBrowser( self::BROWSER_POCKET_IE );
		    $this->setMobile(true);

		    if( stripos($this->_agent,'mspie') !== false ) {
			    $this->setVersion($aresult[1]);
		    }
		    else {
			    $aversion = explode('/',$this->_agent);
			    $this->setVersion($aversion[1]);
		    }
		    return true;
	    }
		return false;
    }
89354
protected function isWhitespaceRequired() {
        $result = false;
        if (!empty($this->compressedCode) && $this->currentPosition < $this->codeLength) {
            $compressedLength = strlen($this->compressedCode);
            $lastChar = $this->compressedCode{$compressedLength - 1};
            $nextChar = $this->code{$this->currentPosition};
            if ($lastChar === '}' && $nextChar === '}' && $compressedLength >= 2) {
                $secondLastChar = $this->compressedCode{$compressedLength - 2};
                $result = ($secondLastChar === '}');
            } else {
                $result = !in_array($lastChar, $this->ignoreFollowingWhitespace)
                    && !in_array($nextChar, $this->ignoreFollowingWhitespace);
            }
        }
        return $result;
    }
1304487
public static function is_token_user_input($t) {
		if (parent::is_token_user_input($t))
			return TRUE;

		if ($t['code'] == T_VARIABLE) {
			if (in_array($t['content'], array(
					'$form', '$form_state'
				)))	return TRUE;
		} elseif ($t['code'] == T_STRING) {
			if (in_array($t['content'], array(
					'arg', 'drupal_get_query_parameters', 'field_view_value'
				))) return TRUE;
		}

		return FALSE;
	}