Converts given punycode to the IDN.
@param string $value punycode to be converted.
@return string resulting IDN.
@since 1.1.13
334825
private function decodeIDN($value)
	{
		if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
		{
			if(function_exists('idn_to_utf8'))
				$value=$matches[1][0].'://'.idn_to_utf8($matches[2][0]).$matches[3][0];
			else
			{
				require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
				$idna=new Net_IDNA2();
				$value=$matches[1][0].'://'.@$idna->decode($matches[2][0]).$matches[3][0];
			}
		}
		return $value;
	}
984258
public function convertFromUrlEncode($value)
    {
        $converted = urldecode($value);
        if (!$converted || $converted === $value) {
            return $value;
        } else {
            return $value . "\n" . $converted;
        }
    }
206628
protected function formatValue($value)
    {
        if (PHP_VERSION_ID < 50400) {
            return str_replace('\/', '/', json_encode($value));
        }

        return json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
493324
protected function _sanitize($value)
    {
        $value = (string) $value;

        // Filter var for XSS and other 'bad' code etc.
        if (!empty($value)) {
            $value = $this->_remove($this->_decode($value));
        }

        return $value;
    }
1324098
public function detokenize(string $value): string
    {
        $count = 1;
        while ($count !== 0) {
            $value = preg_replace(
                '/FUNCTION_START__(.*?)__/',
                '<$1(',
                $value,
                1,
                $count
            );
        }

        $value = preg_replace(
            '/IDENTITY_START/',
            '<(',
            $value
        );
        $value = preg_replace(
            '/IDENTITY_OR_FUNCTION_END/',
            ')>',
            $value
        );

        return $value;
    }
153109
public function encode($value)
    {

        $createdIv = $this->createIvSizeAndIvString();
        $createdKey = $this->createSpecialKey($createdIv);

        if (false !== $encrypted = @mcrypt_encrypt($this->algorithm, $createdKey, $value, $this->mode, $createdIv)) {

            return urlencode(base64_encode(
                serialize(
                    [
                        'iv'    => base64_encode($createdIv),
                        'key'   => base64_encode($createdKey),
                        'value' => trim(base64_encode($encrypted)),
                    ]
                )
            ));
        }

        return false;
    }
451296
public static function convertFromProprietaryEncodings($value)
    {
        //Xajax error reportings
        $value = preg_replace('/<!\[CDATA\[(\W+)\]\]>/im', '$1', $value);

        //strip false alert triggering apostrophes
        $value = preg_replace('/(\w)\"(s)/m', '$1$2', $value);

        //strip quotes within typical search patterns
        $value = preg_replace('/^"([^"=\\!><~]+)"$/', '$1', $value);

        //OpenID login tokens
        $value = preg_replace('/{[\w-]{8,9}\}(?:\{[\w=]{8}\}){2}/', null, $value);

        //convert Content and \sdo\s to null
        $value = preg_replace('/Content|\Wdo\s/', null, $value);

        //strip emoticons
        $value = preg_replace(
            '/(?:\s[:;]-[)\/PD]+)|(?:\s;[)PD]+)|(?:\s:[)PD]+)|-\.-|\^\^/m',
            null,
            $value
        );

        //normalize separation char repetion
        $value = preg_replace('/([.+~=*_\-;])\1{2,}/m', '$1', $value);

        //normalize multiple single quotes
        $value = preg_replace('/"{2,}/m', '"', $value);

        //normalize quoted numerical values and asterisks
        $value = preg_replace('/"(\d+)"/m', '$1', $value);

        //normalize pipe separated request parameters
        $value = preg_replace('/\|(\w+=\w+)/m', '&$1', $value);

        //normalize ampersand listings
        $value = preg_replace('/(\w\s)&\s(\w)/', '$1$2', $value);

        //normalize escaped RegExp modifiers
        $value = preg_replace('/\/\\\(\w)/', '/$1', $value);

        return $value;
    }
860535
protected function getType(&$value)
    {
        switch (true) {
            // Punctuation
            case ($value[0] === ','):
                $type = self::T_COMMA;
                break;

            // Recognize numeric values
            case (is_numeric($value)):
                if (strpos($value, '.') !== false || stripos($value, 'e') !== false) {
                    $value = (float)$value;
                    $type = self::T_FLOAT;
                    break;
                }

                $value = (int)$value;
                $type = self::T_INTEGER;
                break;

            // Recognize quoted strings
            case ($value[0] === '"'):
                $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));

                $type = self::T_STRING;
                break;
            case ($value[0] === "'"):
                $value = str_replace("''", "'", substr($value, 1, strlen($value) - 2));

                $type = self::T_STRING;
                break;

            case (preg_match('/[a-z_][a-z0-9_]*/i', $value)):
                $type = self::T_INPUT_PARAMETER;
                break;

            // Comparison operator
            case ($value === '='):
                $type = self::T_EQUALS;
                break;
            case ($value === '≠'):
            case ($value === '!='):
                $value = '≠';
                $type = self::T_NOT_EQUALS;
                break;
            case ($value === '>'):
                $type = self::T_GREATER_THAN;
                break;
            case ($value === '>='):
            case ($value === '≥'):
                $value = '≥';
                $type = self::T_GREATER_THAN_EQUALS;
                break;
            case ($value === '<'):
                $type = self::T_LOWER_THAN;
                break;
            case ($value === '<='):
            case ($value === '≤'):
                $value = '≤';
                $type = self::T_LOWER_THAN_EQUALS;
                break;

            // Composite operator
            case ($value === '&'):
                $type = self::T_AND;
                break;
            case ($value === '!&'):
                $type = self::T_NOT_AND;
                break;
            case ($value === '|'):
                $type = self::T_OR;
                break;
            case ($value === '!|'):
                $type = self::T_NOT_OR;
                break;
            case ($value === '^|'):
            case ($value === '⊕'):
                $value = '⊕';
                $type = self::T_XOR;
                break;

            // Brace
            case ($value === '('):
                $type = self::T_OPEN_PARENTHESIS;
                break;
            case ($value === ')'):
                $type = self::T_CLOSE_PARENTHESIS;
                break;
            case ($value === '['):
                $type = self::T_OPEN_SQUARE_BRACKET;
                break;
            case ($value === '!['):
                $type = self::T_NOT_OPEN_SQUARE_BRACKET;
                break;
            case ($value === ']'):
                $type = self::T_CLOSE_SQUARE_BRACKET;
                break;
            case ($value === '{{'):
                $type = self::T_DOUBLE_OPEN_CURLY_BRACKET;
                break;
            case ($value === '!{{'):
                $type = self::T_NOT_DOUBLE_OPEN_CURLY_BRACKET;
                break;
            case ($value === '}}'):
                $type = self::T_DOUBLE_CLOSE_CURLY_BRACKET;
                break;

            // Default
            default:
                throw new UnknownTokenTypeException($value);
        }

        return $type;
    }
524647
public static function convertEntities($value)
    {
        $converted = null;
        
        //deal with double encoded payload 
        $value = preg_replace('/&amp;/', '&', $value);     
        
        if (preg_match('/&#x?[\w]+/ms', $value)) {
            $converted = preg_replace('/(&#x?[\w]{2}\d?);?/ms', '$1;', $value);
            $converted = html_entity_decode($converted, ENT_QUOTES, 'UTF-8');
            $value    .= "\n" . str_replace(';;', ';', $converted);
        }
        // normalize obfuscated protocol handlers
        $value = preg_replace(
            '/(?:j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:)|(d\s*a\s*t\s*a\s*:)/ms', 
            'javascript:', $value
        );
        
        return $value;
    }
827080
private function formatValue($value)
    {
        if ($value === '') {
            return '';
        }

        if ($value === null) {
            return '<comment>Null</comment>';
        }

        if (is_bool($value)) {
            return '<comment>' . ($value ? 'True' : 'False') . '</comment>';
        }

        if (empty($value)) {
            return '<comment>Empty</comment>';
        }

        if (is_array($value)) {
            return json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        }

        if (is_object($value)) {
            return sprintf('<%s>', get_class($value));
        }

        if (is_scalar($value)) {
            return $value;
        }

        throw new InvalidArgumentException(sprintf('Do not know how to format value "%s"', print_r($value, true)));
    }
720629
protected function _code93($value)
    {
        $checksum = substr($value, -2, 2);
        $value    = str_split(substr($value, 0, -2));
        $count    = 0;
        $length   = count($value) % 20;
        foreach($value as $char) {
            if ($length == 0) {
                $length = 20;
            }

            $count += $this->_check[$char] * $length;
            --$length;
        }

        $check   = array_search(($count % 47), $this->_check);
        $value[] = $check;
        $count   = 0;
        $length  = count($value) % 15;
        foreach($value as $char) {
            if ($length == 0) {
                $length = 15;
            }

            $count += $this->_check[$char] * $length;
            --$length;
        }
        $check .= array_search(($count % 47), $this->_check);

        if ($check == $checksum) {
            return true;
        }

        return false;
    }
875061
public static function urlEncode($value)
    {
        $result = '';
        for ($i = 0; $i < strlen($value); ++$i) {
            $result .= AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($value[$i])];
        }
        return $result;
    }
448616
private function normalizeValue($value)
    {
        if ($value instanceof NodeInterface) {
            $value = IDEncoder::encode($value);
        } elseif (\is_object($value)) {
            if (method_exists($value, '__toString')) {
                $value = (string) $value;
            } else {
                $value = null;
            }
        }

        return $value;
    }
89002
public function value($value)
    {
        //terminal case
        if (!is_array($value)) {
            if (strpbrk($value, Lexer::ESCAPED_STRING) !== false) {
                if (!(substr($value, 0, 1) == '"' && substr($value, -1) == '"')) {
                    return '(' . addcslashes($value, Lexer::ESCAPED_STRING_PAREN_ENCAPSED) . ')';
                }
            }
            return $value;
        }

        //composite value case
        $pairs = array();
        foreach ($value as $key => $subval) {
            $pairs[] = "{$this->identifier($key)} = {$this->value($subval)}";
        }

        return '(' . implode(', ', $pairs) . ')';
    }
1130567
protected function csvEncode($value)
    {
        if (!$value) {
            return null;
        }
        return implode(
            ',',
            array_map(
                function ($x) {
                    return str_replace(',', '', $x);
                },
                array_values($value)
            )
        );
    }
928980
protected function decodeQuorum($value)
    {
        if (isset(self::$decode[$value])) {
            return self::$decode[$value];
        }

        return $value;
    }
765776
protected static function prepareNumericCast($value)
    {
        if (!in_array(gettype($value), static::$numericCastable, true)) {
            return '';
        }
        if (is_string($value)) {
            return trim($value);
        }
        return $value;
    }