given "rating\\pants" -> "rating\pants"     escape the escape char
171651
public static String removeEscapeChars( String origKey ) {
        StringBuilder sb = new StringBuilder();

        boolean prevWasEscape = false;
        for ( char c : origKey.toCharArray() ) {
            if ( '\\' == c ) {
                if ( prevWasEscape ) {
                    sb.append( c );
                    prevWasEscape = false;
                }
                else {
                    prevWasEscape = true;
                }
            }
            else {
                sb.append( c );
                prevWasEscape = false;
            }
        }

        return sb.toString();
    }
1309267
def escape_value(s):
    '''
    
    '''
    esc = xml.sax.saxutils.escape(s)
    esc = esc.encode('ascii', 'xmlcharrefreplace').decode('ascii')
    esc = RESTRICTED_CHARS.sub('', esc)
    return esc
335487
def _escape_path(key):
    '''
    
    '''
    return _tobytes(key).replace(b'$', b'$_').replace(b'/', b'$+').replace(b'\\', b'$$')
1320187
def _quote_escape(item):
    '''
    
    '''

    rex_sqlquote = re.compile("'", re.M)

    return rex_sqlquote.sub("''", item)
160048
function escape (script) {
  return script.replace(/\\/g, '\\\\').replace(/\n/g, '\\n')
    .replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/"/g, '\\"')
}
557049
private static String escape(char c) {
		switch (c) {
		case '\b':
			return "\\b";
		case '\t':
			return "\\t";
		case '\n':
			return "\\n";
		case '\f':
			return "\\f";
		case '\r':
			return "\\r";
		default:
			if (c < StrUtil.C_SPACE || //
					(c >= '\u0080' && c <= '\u00a0') || //
					(c >= '\u2000' && c <= '\u2010') || //
					(c >= '\u2028' && c <= '\u202F') || //
					(c >= '\u2066' && c <= '\u206F')//
			) {
				return HexUtil.toUnicodeHex(c);
			} else {
				return Character.toString(c);
			}
		}
	}
1160534
@Override
    protected String escapeCharacter(char ch, char previousChar) {
      if(ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r') {
          return "";
      }
      switch(ch) {
          case '&': return ESCAPED_AMP;
          case '<': return ESCAPED_LT;
          case '>': return ESCAPED_GT;
          case '"': return ESCAPED_QUOTE;
          case '\'': return  ESCAPED_APOS;
          case '\\': return  ESCAPED_BACKSLASH;
          case '@': return ESCAPED_AT;
          case '`': return ESCAPED_BACKTICK;
          case NBSP: return ESCAPED_NON_BREAKING_SPACE;
          case LINE_SEPARATOR: return ESCAPED_LINE_SEPARATOR;
          case PARAGRAPH_SEPARATOR: return ESCAPED_PARAGRAPH_SEPARATOR;
      }
      return null;
    }
1301035
private void _appendCharacterEscape(char ch, int escCode)
			throws IOException, JsonGenerationException
	{
		if (escCode >= 0) { // \\N (2 char)
			if ((_outputTail + 2) > _outputEnd) {
				_flushBuffer();
			}
			_outputBuffer[_outputTail++] = '\\';
			_outputBuffer[_outputTail++] = (char) escCode;
			return;
		}
		if (escCode != CharacterEscapes.ESCAPE_CUSTOM) { // std, \\uXXXX
			if ((_outputTail + 5) >= _outputEnd) {
				_flushBuffer();
			}
			int ptr = _outputTail;
			char[] buf = _outputBuffer;
			buf[ptr++] = '\\';
			buf[ptr++] = 'u';
			// We know it's a control char, so only the last 2 chars are non-0
			if (ch > 0xFF) { // beyond 8 bytes
				int hi = (ch >> 8) & 0xFF;
				buf[ptr++] = HEX_CHARS[hi >> 4];
				buf[ptr++] = HEX_CHARS[hi & 0xF];
				ch &= 0xFF;
			} else {
				buf[ptr++] = '0';
				buf[ptr++] = '0';
			}
			buf[ptr++] = HEX_CHARS[ch >> 4];
			buf[ptr++] = HEX_CHARS[ch & 0xF];
			_outputTail = ptr;
			return;
		}
		String escape;
		if (_currentEscape == null) {
			escape = _characterEscapes.getEscapeSequence(ch).getValue();
		} else {
			escape = _currentEscape.getValue();
			_currentEscape = null;
		}
		int len = escape.length();
		if ((_outputTail + len) > _outputEnd) {
			_flushBuffer();
			if (len > _outputEnd) { // very very long escape; unlikely but theoretically possible
				_writer.write(escape);
				return;
			}
		}
		escape.getChars(0, len, _outputBuffer, _outputTail);
		_outputTail += len;
	}
1117078
def re_escape(pattern, chars=frozenset("()[]{}?*+|^$\\.-#")):
    '''
    
    '''
    escape = '\\{}'.format
    return ''.join(
        escape(c) if c in chars or c.isspace() else
        '\\000' if c == '\x00' else c
        for c in pattern
        )
1163450
def _escape_string(text, _map={}):
    
    if isinstance(text, str):
        text = text.encode('ascii')
    assert isinstance(text, (bytes, bytearray))

    if not _map:
        for ch in range(256):
            if ch in _VALID_CHARS:
                _map[ch] = chr(ch)
            else:
                _map[ch] = '\\%02x' % ch
            if six.PY2:
                _map[chr(ch)] = _map[ch]

    buf = [_map[ch] for ch in text]
    return ''.join(buf)
607725
def escape(value, quote=True):
    '''
    
    '''
    def escape_one(match):
        return SPECIAL_CHARS[match.group(0)]

    if isinstance(value, string_types):
        value = SPECIAL_CHARS_REGEX.sub(escape_one, value)
        if quote:
            value = "'" + value + "'"
    return text_type(value)
1087996
def escape(s, quote=True):
    
    s = s.replace("&", "&amp;") # Must be done first!
    s = s.replace("<", "&lt;")
    s = s.replace(">", "&gt;")
    if quote:
        s = s.replace('"', "&quot;")
        s = s.replace('\'', "&#x27;")
    return s
1266913
def escape_string(value):
    
    res = StringIO()
    res.write('"')
    for c in value:
        if c in CHAR_TO_ESCAPE:
            res.write(f'\\{CHAR_TO_ESCAPE[c]}')
        elif c.isprintable():
            res.write(c)
        elif ord(c) < 0x100:
            res.write(f'\\x{ord(c):02x}')
        elif ord(c) < 0x10000:
            res.write(f'\\u{ord(c):04x}')
        else:
            res.write(f'\\U{ord(c):06x}')
    res.write('"')
    return res.getvalue()
1075824
function percentEscape(value) {

    // Percent-escape per specification

    var escapedString = '';

    for (var i = 0; i < value.length; i++) {

        var char = value.charCodeAt(i);

        if ((char >= 48 && char <= 57) ||       // 09
            (char >= 65 && char <= 90) ||       // AZ
            (char >= 97 && char <= 122) ||      // az
            char == 45 ||                       // -
            char == 95 ||                       // _
            char == 46 ||                       // .
            char == 126) {                      // ~

            escapedString += String.fromCharCode(char);
        }
        else {

            escapedString += '%' + char.toString(16).toUpperCase();
        }
    }

    return escapedString;
}
177272
function escapeCommonChars(text) {
  /**
   * Generate new non-escape expression (must happen at execution time because
   * we use `RegExp.exec`, which tracks it's own state internally).
   */
  const nonEscapeExpression = new RegExp(nonEscapePattern, 'gm');

  /**
   * Use `replaceWhen` to escape markdown entities only within substrings that
   * are eligible for escaping.
   */
  return replaceWhen(nonEscapeExpression, escapeAll, text, true);
}
521248
function escapeRegExpCharacter(ch, previousIsBackslash) {
        // not handling '\' and handling \u2028 or \u2029 to unicode escape sequence
        if ((ch & ~1) === 0x2028) {
            return (previousIsBackslash ? 'u' : '\\u') + ((ch === 0x2028) ? '2028' : '2029');
        } else if (ch === 10 || ch === 13) {  // \n, \r
            return (previousIsBackslash ? '' : '\\') + ((ch === 10) ? 'n' : 'r');
        }
        return String.fromCharCode(ch);
    }
602585
def escape(string)
      return "" unless string
      str = string.b
      str.gsub!(/&/n, '&amp;')
      str.gsub!(/\"/n, '&quot;')
      str.gsub!(/>/n, '&gt;')
      str.gsub!(/</n, '&lt;')
      str.force_encoding(string.encoding)
    end