Escapes the inserted value for LDAP.

@param string $value
@param string $ignore
@param int    $flags

@return string
13872
protected function escapeManual($value, $ignore = '', $flags = 0)
    {
        /*
         * If a flag was supplied, we'll send the value
         * off to be escaped using the PHP flag values
         * and return the result.
         */
        if ($flags) {
            return $this->escapeManualWithFlags($value, $ignore, $flags);
        }

        // Convert ignore string into an array
        $ignores = str_split($ignore);

        // Convert the value to a hex string
        $hex = bin2hex($value);

        /*
         * Separate the string, with the hex length of 2,
         * and place a backslash on the end of each section
         */
        $value = chunk_split($hex, 2, '\\');

        /*
         * We'll append a backslash at the front of the string
         * and remove the ending backslash of the string
         */
        $value = '\\'.substr($value, 0, -1);

        // Go through each character to ignore
        foreach ($ignores as $charToIgnore) {
            // Convert the character to ignore to a hex
            $hexed = bin2hex($charToIgnore);

            // Replace the hexed variant with the original character
            $value = str_replace('\\'.$hexed, $charToIgnore, $value);
        }

        // Finally we can return the escaped value
        return $value;
    }
1046920
private function replacementE($value, array $modifiers)
    {
        if (is_array($value)) {
            throw new DataInvalidFormat('escape', 'required string');
        }
        return $this->implementation->escapeString($this->connection, $value);
    }
1138864
public static function escape( $value )
    {
        if ( is_string($value) ){
            $res = htmlspecialchars($value, ENT_QUOTES, mb_internal_encoding());
//log_debug( "debug", "escape:" . print_r($res,true) );
            return $res;
        }
        elseif ( is_array($value) ){
            $ret = array();
            foreach( $value as $key => $item ){
                $ret[$key] = self::escape( $item );
            }
            return $ret;
        }
        elseif ( is_object($value) ){
            $object = $value;
            $vars = get_object_vars($object);
            foreach( $vars as $key => $value ){
                $object->$key = self::escape( $value );
            }
            return $object;
        }
        return $value;
    }
691332
protected function compileEscapedEchos($value)
	{
		$me = $this;

		$pattern = sprintf('/%s\s*(.+?)\s*%s/s', $this->escapedTags[0], $this->escapedTags[1]);

		$callback = function($matches) use ($me)
		{
			return '<?php echo e('.$me->compileEchoDefaults($matches[1]).'); ?>';
		};

		return preg_replace_callback($pattern, $callback, $value);
	}
212830
private function _escape($value, $htmlEntities = false)
    {
        if (get_magic_quotes_gpc()) {
            if ($htmlEntities) {
                return htmlspecialchars($value);
            }

            return $value;
        }

        if (is_array($value)) {
            return array_map(function ($n) use ($htmlEntities) {
                $val = stripslashes($n);

                if ($htmlEntities) {
                    return htmlspecialchars($val);
                }

                return $val;
            }, $value);
        }
        $val = stripslashes($value);

        if ($htmlEntities) {
            return htmlspecialchars($val);
        }

        return $val;
    }
754794
public function whereRegexp($field, $value, $flags = 'ALL')
    {
        $this->wheres['must'][] = [
            'regexp' => [
                $field => [
                    'value' => $value,
                    'flags' => $flags,
                ],
            ],
        ];

        return $this;
    }
194788
public function ldapEscape($subject, $dn = false, $ignore = null) {
		// The base array of characters to escape
		// Flip to keys for easy use of unset()
		$search = array_flip($dn ? ['\\', ',', '=', '+', '<', '>', ';', '"', '#'] : ['\\', '*', '(', ')', "\x00"]);

		// Process characters to ignore
		if (is_array($ignore)) {
			$ignore = array_values($ignore);
		}
		for ($char = 0; isset($ignore[$char]); $char++) {
			unset($search[$ignore[$char]]);
		}

		// Flip $search back to values and build $replace array
		$search = array_keys($search);
		$replace = [];
		foreach ($search as $char) {
			$replace[] = sprintf('\\%02x', ord($char));
		}

		// Do the main replacement
		$result = str_replace($search, $replace, $subject);

		// Encode leading/trailing spaces in DN values
		if ($dn) {
			if ($result[0] == ' ') {
				$result = '\\20' . substr($result, 1);
			}
			if ($result[strlen($result) - 1] == ' ') {
				$result = substr($result, 0, -1) . '\\20';
			}
		}

		return $result;
	}
780926
protected function modifyFlagValue($value)
    {
        $this->setDefaultLastValue($this->getEnumAttribute(), $this->getDefaultEnumValue());
        $flags = $this->getFlagFromLastValue($this->getLastValue());

        $value = $this->options['invert'] ? !$value : $value;
        if ($value) {
            $flags->add($this->flagName);
        } else {
            $flags->remove($this->flagName);
        }

        return $flags->getValue();
    }
925374
protected static function maskHasFlag($mask, $flag)
    {
        $flag   = (int)$flag;
        return ((int)$mask & $flag) === $flag;
    }
1265597
public static function isOn($value, $flag)
    {
        if (!Int::is($value)) {
            throw new \InvalidArgumentException("The \$value parameter must be of type int.");
        }

        if (!static::is($flag)) {
            throw new \InvalidArgumentException("The \$flag parameter must be of type int and a power of 2.");
        }

        return static::is($value & $flag);
    }
845899
protected function prepareRegexRule($value)
    {
        $escape = ['$' => '\$', '?' => '\?', '.' => '\.', '*' => '.*'];
        foreach ($escape as $search => $replace) {
            $value = str_replace($search, $replace, $value);
        }
        if (mb_strlen($value) > 2 && mb_substr($value, -2) == '\$') {
            $value = substr($value, 0, -2) . '$';
        }
        if (mb_strrpos($value, '/') == (mb_strlen($value) - 1)
            || mb_strrpos($value, '=') == (mb_strlen($value) - 1)
            || mb_strrpos($value, '?') == (mb_strlen($value) - 1)
        ) {
            $value .= '.*';
        }

	    if (substr($value, 0, 2) != '.*') {
		    $value = '^' . $value;
	    }
        return $value;
    }
968948
private static function jsonEncode($value, int $flags = null, int $maxDepth = 512): string
    {
        $flags = $flags ?? (JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT | JSON_PRESERVE_ZERO_FRACTION);

        if (!\is_array($value) && !$value instanceof \JsonSerializable) {
            throw new InvalidArgumentException(sprintf('Option "json" must be array or JsonSerializable, %s given.', \is_object($value) ? \get_class($value) : \gettype($value)));
        }

        try {
            $value = json_encode($value, $flags | (\PHP_VERSION_ID >= 70300 ? JSON_THROW_ON_ERROR : 0), $maxDepth);
        } catch (\JsonException $e) {
            throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', $e->getMessage()));
        }

        if (\PHP_VERSION_ID < 70300 && JSON_ERROR_NONE !== json_last_error() && (false === $value || !($flags & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
            throw new InvalidArgumentException(sprintf('Invalid value for "json" option: %s.', json_last_error_msg()));
        }

        return $value;
    }
643936
protected function getLdapControl($value)
    {
        $values = explode(' ', $value);

        // This should never happen, but it seems better to cover it in case...
        if (empty($values) || $values === false) {
            $this->throwException(sprintf('Expecting a LDAP control but got "%s"', $value));
        }
        // The first value should be an actual OID...
        if (!preg_match(LdapUtilities::MATCH_OID, $values[0])) {
            $this->throwException(sprintf('The control directive has an invalid OID format "%s"', $values[0]));
        }

        $control = new LdapControl($values[0]);
        if (isset($values[1])) {
            $control->setCriticality($this->getBoolFromStringBool($values[1]));
        }
        if (isset($values[2])) {
            $control->setValue($values[2]);
        }

        return $control;
    }
529521
protected function serializeValue($value)
    {
        if ($this->isSerializable($value) === true) {
            // Activate default bit to detect serialization
            $value = serialize($value);
            $bytes = strlen($value);
            $flags = self::FLAG_DECIMAL_SERIALIZED;

        } else {
            // Real numbers should keep real numbers - Bit 2 = int , 3 = double/float
            if (is_int($value) === true) {
                $flags = self::FLAG_DECIMAL_INTEGER;

            } elseif (is_float($value) === true) {
                $flags = self::FLAG_DECIMAL_FLOAT;

            } elseif (is_string($value) === true) {
                // Never serialize strings! Otherwise append() & prepend() won't work!
                $flags = self::FLAG_DECIMAL_STRING;

            } elseif (is_bool($value) === true) {
                $value = strval($value);
                $flags = self::FLAG_DECIMAL_BOOLEAN;

            } else {
                throw new Exception(
                    sprintf('Unhandable value. Don\'t know how to process!')
                );
            }

            $bytes = strlen($value);
        }

        return array(
            'value' => $value,
            'flags' => $flags,
            'bytes' => $bytes,
        );
    }
272960
public function scanType( $value, $flagSpecial=false ) {
		$this->svalue=$value;
		if ($value===false) return self::C_DATATYPE_INTEGER;
		if ($value===null) return self::C_DATATYPE_INTEGER; //for fks
		if ($this->startsWithZeros($value)) return self::C_DATATYPE_TEXT;
		if (is_numeric($value) && (intval($value)==$value) && $value<2147483648) return self::C_DATATYPE_INTEGER;
		if ((is_numeric($value) && $value < 2147483648)
				  || preg_match('/\d{4}\-\d\d\-\d\d/',$value)
				  || preg_match('/\d{4}\-\d\d\-\d\d\s\d\d:\d\d:\d\d/',$value)
		) {
			return self::C_DATATYPE_NUMERIC;
		}
		return self::C_DATATYPE_TEXT;
	}
665527
public function grep($values, $pattern, $flags = '')
    {
        if (!isset($values)) {
            return null;
        }
        
        if (is_string($flags)) {
            $flags = $flags === 'invert' ? PREG_GREP_INVERT : 0;
        }
        
        return preg_grep($pattern, $values, $flags);
    }
1002502
protected function escapeValue($value, $type = null){
		if(!$type){
			// NULL type
			if($value === null)
				return 'NULL';

			// Array of values w/o types
			elseif(is_array($value)){
				foreach($value as $k => $v)
					$value[$k] = $this->escapeValue($v);
				return $value;
			}

			// Value w/o type
			else{
				if($value instanceof DateTime){
					return $this->escapeValue($value, Manager::DATETIME);
				} elseif($value instanceof Literal){
					return $value->value;
				} elseif(is_bool($value)){
					return $this->stmt->getConnection()->getDriver()->escape($value, Manager::BOOL);
				} else{
					return is_numeric($value)
						? +$value
						: $this->stmt->getConnection()->getDriver()->escape($value, Manager::TEXT);
				}
			}
		}

		// Multiple values w/ types
		elseif(is_array($type)){
			foreach($value as $k => $v)
				$value[$k] = $this->escapeValue($v, $type[$k]);
			return $value;
		}

		// Single value w/ type
		elseif($type !== null){
			if($type === Manager::INT){
				return (int) $value;
			} elseif($type === Manager::FLOAT){
				return (float) $value;
			} elseif($type === Manager::SUBQUERY && $value instanceof Result){
				return "(\n\t" . implode("\n\t", explode("\n", $value)) . "\n)";
			} elseif($type === Manager::ARR){
				$arr = $value instanceof Traversable ? iterator_to_array($value) : (array) $value;
				return '(' . implode(', ', $this->escapeValue($arr)) . ')';
			} elseif($type === Manager::LITERAL){
				return $value instanceof Literal ? $value->value : $value;
			} else{
				return $this->stmt->getConnection()->getDriver()->escape($value, $type);
			}
		}
	}