/*
Escapes all occurences of the ':' character from the input, replacing them by "\:".
Furthermore, if the last character is '\' or '!', a '!' is appended.
346958
public static String escape(String input)
    {
        if (input.isEmpty())
            return input;

        String res = input.replaceAll(":", "\\\\:");
        char last = res.charAt(res.length() - 1);
        return last == '\\' || last == '!' ? res + '!' : res;
    }
160048
function escape (script) {
  return script.replace(/\\/g, '\\\\').replace(/\n/g, '\\n')
    .replace(/\r/g, '\\r').replace(/\t/g, '\\t').replace(/"/g, '\\"')
}
921929
function () {
                    var str, j = i, e, index = i;

                    if (input.charAt(j) === '~') { j++; e = true; } // Escaped strings
                    if (input.charAt(j) !== '"' && input.charAt(j) !== "'") { return; }

                    if (e) { $char('~'); }

                    str = $re(/^"((?:[^"\\\r\n]|\\.)*)"|'((?:[^'\\\r\n]|\\.)*)'/);
                    if (str) {
                        return new(tree.Quoted)(str[0], str[1] || str[2], e, index, env.currentFileInfo);
                    }
                }
87389
function escapeHtmlChars(text) 
{
    let ast = myna.parsers.html_reserved_chars(text);
    if (!ast.children)    
        return "";
    return ast.children.map(astNodeToHtmlText).join('');
}
1031600
function escapestr(s) {
            return s.replace(/\\/g, '\\\\')
                    .replace(/'/g, '\\\'')
                    .replace(/"/g, '\\"')
                    .replace(/\r/g, '\\r')
                    .replace(/\n/g, '\\n');
        }
945356
function(input) {
            return (""+input).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
        }
376914
def javascript_escape(s, quote_double_quotes=True):
    
    ustring_re = re.compile(u"([\u0080-\uffff])")

    def fix(match):
        return r"\u%04x" % ord(match.group(1))

    if type(s) == str:
        s = s.decode('utf-8')
    elif type(s) != six.text_type:
        raise TypeError(s)
    s = s.replace('\\', '\\\\')
    s = s.replace('\r', '\\r')
    s = s.replace('\n', '\\n')
    s = s.replace('\t', '\\t')
    s = s.replace("'", "\\'")
    if quote_double_quotes:
        s = s.replace('"', '&quot;')
    return str(ustring_re.sub(fix, s))
5229
function escapeChars(text) {
        var r = JSON.stringify(text);
        return r.slice(1, r.length - 1);
    }
1171322
function regEscape(str) {
  // essentially stolen from https://github.com/component/escape-regexp with a modified replacer
  return String(str).replace(/([.*+?=^!:${}()|[\]\/\\])/g, function (match, paren, index, orig) {
    if (match === ':' && orig[index + 1] !== '/')
      return match;
    
    // if star, it's a wildcard if only enclosed by forward slashes (or at start or end of string)
    if (match === '*' && (index === 0 || orig[index - 1] === '/') && (index + 1 === orig.length || orig[index + 1] === '/'))
      return '.*';
    
    return '\\' + match;
  });
}
641015
def char_to_a(char: "\s", strip: true)
      escaped = char.regexp_escape
      split(/(?<!\\)#{escaped}/).map do |v|
        strip ? v.gsub(/\\#{escaped}/, char) : v
      end
    end
1018303
function(s) {
    return '"' + s.replace(/[\u0000-\u001f"\\\u007f-\uffff]/g, function (c) {
      switch (c) {
      case '\b':
        return '\\b';
      case '\f':
        return '\\f';
      case '\n':
        return '\\n';
      case '\r':
        return '\\r';
      case '\t':
        return '\\t';
      // IE doesn't support this
      /*
      case '\v':
        return '\\v';
      */
      case '"':
        return '\\"';
      case '\\':
        return '\\\\';
      default:
        return '\\u' + jscoverage_pad(c.charCodeAt(0).toString(16));
      }
    }) + '"';
  }
719376
def escape_filter_chars(assertion_value, escape_mode=0):
    

    if isinstance(assertion_value, six.text_type):
        assertion_value = assertion_value.encode("utf_8")

    s = []
    for c in assertion_value:
        do_escape = False

        if str != bytes:  # Python 3
            pass
        else:  # Python 2
            c = ord(c)

        if escape_mode == 0:
            if c == ord('\\') or c == ord('*') \
                    or c == ord('(') or c == ord(')') \
                    or c == ord('\x00'):
                do_escape = True
        elif escape_mode == 1:
            if c < '0' or c > 'z' or c in "\\*()":
                do_escape = True
        elif escape_mode == 2:
            do_escape = True
        else:
            raise ValueError('escape_mode must be 0, 1 or 2.')

        if do_escape:
            s.append(b"\\%02x" % c)
        else:
            b = None
            if str != bytes:  # Python 3
                b = bytes([c])
            else:  # Python 2
                b = chr(c)
            s.append(b)

    return b''.join(s)
921832
public static final String escape(String s) {
        StringBuilder buf = new StringBuilder();
        for (int i=0; i<s.length(); ) {
            int c = Character.codePointAt(s, i);
            i += UTF16.getCharCount(c);
            if (c >= ' ' && c <= 0x007F) {
                if (c == '\\') {
                    buf.append("\\\\"); // That is, "\\"
                } else {
                    buf.append((char)c);
                }
            } else {
                boolean four = c <= 0xFFFF;
                buf.append(four ? "\\u" : "\\U");
                buf.append(hex(c, four ? 4 : 8));
            }
        }
        return buf.toString();
    }
1373905
function escapeDelimiters(pattern, text) {
  return text.replace(pattern, (match, start, end) => {
    const hasEnd = typeof end === 'string';
    const matchSliceEnd = hasEnd ? match.length - end.length : match.length;
    const content = match.slice(start.length, matchSliceEnd);
    return `${escape(start)}${content}${hasEnd ? escape(end) : ''}`;
  });
}
190730
public static final String escapeString(final String delimiter,
            final String input) {
        final String escaped = escapeString(input);
        if (escaped.isEmpty()) {
            return escaped;
        }
        return delimiter + escaped;
    }
811601
function escape(string) {
  return string.replace(/[^]/g, char => {
    const code = char.charCodeAt();

    if (code < 256) return char;

    const escape = code.toString(16);
    const long = escape.length > 2;
    return `\\${long ? 'u' : 'x'}${('0000' + escape).slice(long ? -4 : -2)}`;
  });
}
1250144
private String escapeSpecialCharacters(final String string) {
		final StringBuilder escaped = new StringBuilder();
		for (final char character : string.toCharArray()) {
			if (character == '%' || character == '_' || character == '\\') {
				escaped.append('\\');
			}
			escaped.append(character);
		}
		return escaped.toString();
	}