handle escaped characters (backslashes) in a string
507703
function evalString(text) {
      if (text.lastIndexOf('\\') < 0)
        return text;
      return text.replace(/\\\\/g, '\\')
                 .replace(/\\n/g, '\n')
                 .replace(/\\r/g, '\r')
                 .replace(/\\t/g, '\t')
                 .replace(/\\b/g, '\b')
                 .replace(/\\f/g, '\f')
                 .replace(/\\{/g, '{')
                 .replace(/\\}/g, '}')
                 .replace(/\\"/g, '"')
                 .replace(/\\'/g, "'");
    }
859916
def escape_path(str)
      result = ""
      str.scan(%r{/([^/]*)}).each{|i|
        result << "/" << _escape(i[0], UNESCAPED_PCHAR)
      }
      return result
    end
649212
def escape_unicode_string(u):
    
    def replacer(matchobj):
        if ord(matchobj.group(1)) == 127:
            return "\\x7f"
        if ord(matchobj.group(1)) == 92: # backslash
            return "\\\\"
        return REPLACEMENT_TABLE[ord(matchobj.group(1))]
    return re.sub("([\\000-\\037\\134\\177])", replacer, u)
612149
def escape_string_json(st):
    
    ret = []
    c = 0
    ln = len(st)

    escape_chmap = {
        b'\b': b'b',
        b'\f': b'f',
        b'\n': b'n',
        b'\r': b'r',
        b'\t': b't',
        b'\\': b'\\',
        b'\"': b'"',
        b'\/': b'/'
    }

    while c < ln:
        ch = st[c:c+1]
        if ch in escape_chmap:
            ret.append(b'\\' + escape_chmap[ch])
        elif ord(ch) < 0x20:
            ret.append(b'\\u%04X' % ord(ch))
        else:
            ret.append(ch)
        c += 1
    return b''.join(ret)
500309
private String escapeAttributeNameSpecialCharacters(String str)
    {
        if (str != null)
        {
            StringBuffer strBuf = new StringBuffer("");

            for (int i = 0; i < str.length(); i++)
            {
                char strChar = str.charAt(i);

                switch (strChar)
                {
                    case ':':
                        {
                            strBuf.append("_ns-sep_");
                            break;
                        }
                    default:
                        {
                            strBuf.append(strChar);
                            break;
                        }
                }
            }
            str = strBuf.toString();
        }
        return str;
    }
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;
    }
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}'
564033
function escape (string) {
  return string
    .replace(/ /g, '\\ ')
    .replace(/\n/g, '')
    .replace(/\(/g, '\\(')
    .replace(/\)/g, '\\)');
}
238802
function escape(string) {
  var snippets = [];

  // Replace all code snippets with a token.
  string = string.replace(reCode, function(match) {
    snippets.push(match);
    return token;
  });

  _.forOwn(htmlEscapes, function(replacement, chr) {
    string = string.replace(RegExp('(\\\\?)\\' + chr, 'g'), function(match, backslash) {
      return backslash ? match : replacement;
    });
  });

  // Replace all tokens with code snippets.
  return string.replace(reToken, function(match) {
    return snippets.shift();
  });
}
5229
function escapeChars(text) {
        var r = JSON.stringify(text);
        return r.slice(1, r.length - 1);
    }
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
        )
653125
function escapeString(string) {
  var result = '';
  var char;
  var escapeSeq;

  for (var i = 0; i < string.length; i++) {
    char = string.charCodeAt(i);
    escapeSeq = ESCAPE_SEQUENCES[char];
    result += !escapeSeq && isPrintable(char)
      ? string[i]
      : escapeSeq || encodeHex(char);
  }

  return result;
}
742129
def unescape(str):
    """"""
    out = ''
    prev_backslash = False
    for char in str:
        if not prev_backslash and char == '\\':
            prev_backslash = True
            continue
        out += char
        prev_backslash = False
    return out
273303
def escape_dn_chars(s):
    
    if s:
        assert isinstance(s, six.string_types)
        s = s.replace('\\', '\\\\')
        s = s.replace(',', '\\,')
        s = s.replace('+', '\\+')
        s = s.replace('"', '\\"')
        s = s.replace('<', '\\<')
        s = s.replace('>', '\\>')
        s = s.replace(';', '\\;')
        s = s.replace('=', '\\=')
        s = s.replace('\000', '\\\000')
        if s[0] == '#' or s[0] == ' ':
            s = ''.join(('\\', s))
        if s[-1] == ' ':
            s = ''.join((s[:-1], '\\ '))
    return s
61494
function unescapeString(str) {
    let i = 0, result = '';
    const len = str.length;

    while (i < len) {
        const ch = str[i++];
        result += (ch === '\\') ? (str[i++] || '') : ch;
    }

    return result;
}
65916
def _stripslashes(s):
  ''''''
  r = re.sub(r"\\(n|r)", "\n", s)
  r = re.sub(r"\\", "", r)
  return r
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