Escapes a given string as a literal

@param string $literal
@return string
765356
static public function escapeLiteral(string $literal): string {
        self::initSerializer();
        $value = self::$serializer->serialiseValue(new Literal($literal));
        return $value;
    }
324621
protected function escape($str)
	{
		$str = str_replace('\\', '\\\\', $str);
		$str = str_replace('+', '\+', $str);
		$str = str_replace('-', '\-', $str);
		$str = str_replace('&&', '\&&', $str);
		$str = str_replace('||', '\||', $str);
		$str = str_replace('!', '\!', $str);
		$str = str_replace('(', '\(', $str);
		$str = str_replace(')', '\)', $str);
		$str = str_replace('{', '\{', $str);
		$str = str_replace('}', '\}', $str);
		$str = str_replace('[', '\[', $str);
		$str = str_replace(']', '\]', $str);
		$str = str_replace('^', '\^', $str);
		$str = str_replace('"', '\"', $str);
		$str = str_replace('~', '\~', $str);
		$str = str_replace('*', '\*', $str);
		$str = str_replace('?', '\?', $str);
		$str = str_replace(':', '\:', $str);
		
		$str = str_ireplace(
			array(' and ', ' or ', ' not ', ' to '),
			'',
			$str
		);
		
		return $str;
	}
381638
protected function _escapeTrace($Trace)
    {
        if (!$Trace) return $Trace;
        for( $i=0 ; $i<sizeof($Trace) ; $i++ ) {
            if (isset($Trace[$i]['file'])) {
                $Trace[$i]['file'] = $this->_escapeTraceFile($Trace[$i]['file']);
            }
            if (isset($Trace[$i]['args'])) {
                $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']);
            }
        }
        return $Trace;    
    }
583201
public static function escape(string $argument) : string
    {
        if (!Platform::isWindows()) {
            return preg_match('{^[\w-]+$}', $argument) ? $argument : escapeshellarg($argument);
        }

        // Windows
        // Fix for PHP bug #49446 {@see https://bugs.php.net/bug.php?id=49446}
        // Fix for PHP bug #43784 {@see https://bugs.php.net/bug.php?id=43784}
        $result = '';

        foreach (preg_split('/([%"])/i', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
            if ('"' == $part) {
                $result .= '\\"';
            } elseif ('%' == $part) {
                $result .= '^%';
            } else {
                $result .= escapeshellarg($part);
            }
        }

        return $result;
    }
992209
def _escape_regexp(s):
    """"""
    return (
        str(s)
        .replace('|', '\\|')
        .replace('.', '\.')  # `.` has to be replaced before `*`
        .replace('*', '.*')
        .replace('+', '\+')
        .replace('(', '\(')
        .replace(')', '\)')
        .replace('$', '\\$')
    )
1215061
public function escape($string)
    {
        if (is_string($string)) {
            $func = $this->escape;
            return $func($string);
        }
        return $string;
    }
873740
public static function escape( $value, $escapeNull = true )
    {

        if( $value === null ) {
            return $escapeNull ? self::ESCAPE_CHARACTER . self::NULL_CHARACTER : '';
        }

        $value = str_replace( self::ESCAPE_CHARACTER, self::ESCAPE_CHARACTER . self::ESCAPE_CHARACTER, $value );
        $value = str_replace( self::RANGE_SEPARATOR, self::ESCAPE_CHARACTER . self::RANGE_SEPARATOR, $value );
        $value = str_replace( self::INTERVAL_SEPARATOR, self::ESCAPE_CHARACTER . self::INTERVAL_SEPARATOR, $value );

        return $value;

    }
264805
def escape(cls, string):
        

        return ''.join([cls._escapes[c] if cls._needescape(c) else c
                        for c in string.encode('utf8')])
489451
protected function escape($input)
    {
        return str_replace(
            $this->quotechar,
            $this->escapechar . $this->quotechar,
            $input
        );
    }
1250434
public static function quote($value)
    {
        $escapedValue = preg_quote($value);
        if (substr_count($escapedValue, '/') && !substr_count($escapedValue, '\/')) {
            $escapedValue = str_replace('/', '\/', $escapedValue);
        }

        return $escapedValue;
    }
3082
public static String escape(String literal)
    {
        StringBuilder sb = new StringBuilder();
        for (int ii = 0; ii < literal.length(); ii++)
        {
            char cc = literal.charAt(ii);
            switch (cc)
            {
                case '[':
                case ']':
                case '(':
                case ')':
                case '\\':
                case '-':
                case '^':
                case '*':
                case '+':
                case '?':
                case '|':
                case '.':
                case '{':
                case '}':
                case '&':
                case '$':
                case ',':
                    sb.append("\\").append(cc);
                    break;
                default:
                    sb.append(cc);
                    break;
            }
        }
        return sb.toString();
    }
788906
public function escape_string($value)
    {
        if ($this->pdo) {
            return substr($this->pdo->quote($value), 1, -1);
        }
        return $value;
    }
1255659
public function escapeString($string)
    {
        if (func_num_args() < 2) {
            if (strpos($string, "\n") !== false) {
                return array('{' . strlen($string) . '}', $string);
            } else {
                return '"' . str_replace(array('\\', '"'), array('\\\\', '\\"'), $string) . '"';
            }
        }
        $result = array();
        foreach (func_get_args() as $string) {
            $result[] = $this->escapeString($string);
        }
        return $result;
    }
1264268
private function escapeOtherCharacters($line)
    {
        $escapable = array('<!--');

        foreach ($escapable as $i)
        {
            if (strpos($line, $i) !== false)
            {
                // Found an escapable character, escaping it
                $line = substr_replace($line, '\\', strpos($line, $i), 0);
            }
        }

        return $line;
    }
945817
public static function escape( $value )
	{
		if ( $value instanceof Htmlable )
			return $value->toHtml();

		return htmlentities( $value, ENT_QUOTES, 'UTF-8', false );
	}
708457
def escape_string(self, string):
        """"""
        if self.quote:
            quote = self.quote
        else:
            found = QUOTE_REGEX.search(string)
            quote = STRING_QUOTES[found.group()] if found else next(iter(STRING_QUOTES))

        for match, seq in ESCAPE_SUBS.items():
            if match == quote or match not in STRING_QUOTES:
                string = string.replace(match, seq)

        return f'{quote}{string}{quote}'
655656
public function literal($string) {
        $string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose . $this->_quoteChar);
        return $string;
    }