Escape string values.

@param string $value The string to escape.
@param boolean $quote If the string should be quoted or not.
@return string
517804
public function escapeStringValue($value, $quote = true)
    {
        $output = addcslashes((string)$value, "'");
        if ($quote === true) {
            $output = "'" . $output . "'";
        }

        return $output;
    }
661103
function EscapeValue($value)
    {
        if ($value === null)
            return 'NULL';
        
        if ($value instanceof Date)
            $value = $value->ToString( 'Y-m-d H:i:s');

        return "'" . $this->db->real_escape_string($value) . "'";
    }
1217987
def _escape(value):
        
        value = str(value)
        for char, escaped in {' ': '\ ', ',': '\,', '"': '\"'}.items():
            value = value.replace(char, escaped)
        return value
211472
public static String escape(final String value) {
        final StringBuilder builder = new StringBuilder();
        for (final char ch : value.toCharArray()) {
            builder.append(ESCAPES.containsKey(ch) ? ESCAPES.get(ch) : ch);
        }
        return builder.toString();
    }
1207227
public function quoteIdentifier($value)
    {
        if ($value instanceof Expr) {
            return $value->getValue();
        }

        if ($value === '*') {
            return $value;
        }

        $pieces = explode('.', $value);

        foreach ($pieces as $key => $piece) {
            $pieces[$key] = '`'.$piece.'`';
        }

        return implode('.', $pieces);
    }
901614
protected function parseValue($value) {
        if(is_string($value)) {
            $value =  strpos($value,':') === 0 && in_array($value,array_keys($this->bind))? $this->escapeString($value) : '\''.$this->escapeString($value).'\'';
        }
        elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
            $value =  $this->escapeString($value[1]);
        }
        elseif(is_array($value)) {
            $value =  array_map([$this, 'parseValue'],$value);
        }
        elseif(is_bool($value)){
            $value =  $value ? '1' : '0';
        }
        elseif(is_null($value)){
            $value =  'null';
        }
        return $value;
    }
182559
public static String quote(final String value) {
        if (value == null) {
            return null;
        }
        String result = value;
        if (!result.startsWith("\"")) {
            result = "\"" + result;
        }
        if (!result.endsWith("\"")) {
            result = result + "\"";
        }
        return result;
    }
630664
public function escape($value)
    {
        if (is_numeric($value)) {
            return $value;
        }

        return is_string($value) ? htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false) : $value;
    }
541490
public function quoteIdentifier($value)
    {
        $quote = false;
        switch ($this->getConfig()->get(Formatter::CFG_QUOTE_IDENTIFIER_STRATEGY)) {
            case Formatter::QUOTE_IDENTIFIER_AUTO:
                $quote = ReservedWords::isReserved($value);
                break;

            case Formatter::QUOTE_IDENTIFIER_ALWAYS:
                $quote = true;
                break;
        }

        return $quote ? '`'.$value.'`' : $value;
    }
1068072
def escape(value)
      if value.class == String
        value.gsub(/['"&<>]/) do |match|
          CONVERSION_TABLE.assoc(match).last
        end
      else
        value
      end
    end
87917
private static function stringify($value)
    {
        if (is_string($value)) {
            return sprintf('"%s"', preg_replace('/\n/', '\n', $value));
        }

        if (is_bool($value)) {
            return $value ? 'true' : 'false';
        }

        if (is_null($value)) {
            return 'null';
        }

        if (is_array($value)) {
            return sprintf('[%s]', implode(', ', array_map(
                function ($value) {
                    return self::stringify($value);
                },
                $value
            )));
        }

        return (string) $value;
    }
663029
private function getSanitisedValue($value)
    {
        if ($this->beginsWithQuote($value)) {

            $quote = $value[0];

            $regexPattern = sprintf(
                '/^
                %1$s          # match a quote at the start of the value
                (             # capturing sub-pattern used
                 (?:          # we do not need to capture this
                  [^%1$s\\\\] # any character other than a quote or backslash
                  |\\\\\\\\   # or two backslashes together
                  |\\\\%1$s   # or an escaped quote e.g \"
                 )*           # as many characters that match the previous rules
                )             # end of the capturing sub-pattern
                %1$s          # and the closing quote
                .*$           # and discard any string after the closing quote
                /mx',
                $quote
            );

            $value = preg_replace($regexPattern, '$1', $value);
            $value = str_replace("\\$quote", $quote, $value);
            $value = str_replace('\\\\', '\\', $value);

            return $value;
        }

        $parts = explode(' #', $value, 2);
        $value = trim($parts[0]);

        if (preg_match('/\s+/', $value) > 0) {
            throw new InvalidArgumentException('DotEnv values containing spaces must be surrounded by quotes.');
        }

        return $value;
    }
366449
static String escape(String value) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            String replacement = REPLACEMENTS.get(c);
            if (replacement != null) {
                builder.append(replacement);
            } else {
                builder.append(c);
            }
        }
        return builder.toString();
    }
1024905
private void escape(String value) {
        int n = value.length();
        int i = 0;
        for (int j = 0; j < n; ++j) {
            char c = value.charAt(j);
            int k = ESCAPED_CHARS.indexOf(c);
            if (k >= 0 || c < ' ') {
                if (i < j) {
                    append(value, i, j);
                }
                if (k >= 0) {
                    append(ESCAPE_SEQ[k]);
                } else {
                    append("\\u");
                    append(String.format("%04x", Integer.valueOf(c)));
                }
                i = j + 1;
            }
        }
        if (i < n) {
            append(value, i, n);
        }
    }
400221
protected function quotedAttributeValue($quote) {
        $stoplist = "\f" . $quote;
        $val = '';
        $tok = $this->scanner->current();
        while (strspn($tok, $stoplist) == 0 && $tok !== false) {
            if ($tok == '&') {
                $val .= $this->decodeCharacterReference(true);
                $tok = $this->scanner->current();
            } else {
                $val .= $tok;
                $tok = $this->scanner->next();
            }
        }
        $this->scanner->next();
        return $val;
    }
1097758
public static String escape(String value) {
        for (int i = 0; i < value.length(); i++) {
            if (isEscapingChar(value.charAt(i))) {
                return doEscape(value.getBytes(StandardCharsets.UTF_8), i);
            }
        }
        return value;
    }
463223
function quote($value)
  {
    if ($value === null)
      return 'null';

    assert (!is_object($value));

    if (is_bool($value))
      return (int) $value;

    // Protect digit sequences beginning with '0' (eg phone numbers)
    if (is_string($value) && substr($value, 0,1) == "0")
     return "'".$this->real_escape_string($value)."'";

    if (is_numeric($value))
      return $value;

    // Create comma separated lists for arrays.
    if (is_array($value))
    {
      $res = [];
      foreach ($value as $v)
      {
        if (is_array($v))
          $res[] = "(".$this->quote($v).")";
        else
          $res[] = $this->quote($v);
      }
      return implode(",",$res);
    }

    return "'".$this->real_escape_string($value)."'";
  }