init table with charactets to be escaped
359144
private void initBracketMap() {
		escMap.put("(", "-LRB-");
		escMap.put(")", "-RRB-");
		escMap.put("{", "-LCB-");
		escMap.put("}", "-RCB-");
		escMap.put("[", "-LSB-");
		escMap.put("]", "-RSB-");
	}
791285
def escape_chars(text, chars):
    """"""
    text = str(text)
    chars = list(set(chars))
    if '\\' in chars:
        chars.remove('\\')
        chars.insert(0, '\\')
    for ch in chars:
        text = text.replace(ch, '\\' + ch)
    return text
36210
def escape_control_chars_in_object!(object)
      case object
      when String
        escape_control_chars!(object)
      when Hash
        escape_control_chars_in_hash!(object)
      when Array
        escape_control_chars_in_array!(object)
      else
        object
      end
    end
663926
def _escape_sequence(self, char):
        

        num = ord(char)
        if char == "[":
            self.state = "escape-lb"
        elif char == "(":
            self.state = "charset-g0"
        elif char == ")":
            self.state = "charset-g1"
        elif num in self.escape:
            self.dispatch(self.escape[num])
            self.state = "stream"
        elif self.fail_on_unknown_esc:
            raise StreamProcessError("Unexpected character '%c' == '0x%02x'" % (char, ord(char)))
625532
def unescape(self):
        
        for i, k in enumerate(self._html_escape_table):
            v = self._html_escape_table[k]
            self.obj = self.obj.replace(v, k)

        return self._wrap(self.obj)
665909
def _escape_char(c):
    ""
    if isinstance(c, int):
        c = _unichr(c)
    return c if c in LEGAL_CHARS else ESCAPE_FMT % ord(c)
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;
    }
495423
def unescape_sql(inp):
    
    if inp.startswith('"') and inp.endswith('"'):
        inp = inp[1:-1]
    return inp.replace('""','"').replace('\\\\','\\')
382497
private static String escapeJavaScriptChars(String s) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            switch (ch) {
                case '\b':
                    sb.append("\\b");
                    break;
                case '\t':
                    sb.append("\\t");
                    break;
                case '\n':
                    sb.append("\\n");
                    break;
                case '\f':
                    sb.append("\\f");
                    break;
                case '\r':
                    sb.append("\\r");
                    break;
                case '"':
                    sb.append("\\\"");
                    break;
                case '\'':
                    sb.append("\\\'");
                    break;
                case '\\':
                    sb.append("\\\\");
                    break;
                default:
                    if (ch < 32 || ch >= 127) {
                        sb.append(String.format("\\u%04X", (int)ch));
                    } else {
                        sb.append(ch);
                    }
                    break;
            }
        }
        return sb.toString();
    }
188215
function sanitizeInput(input) {
  // http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html [4.1.2.1-4.1.2.2]
  // single quotes (') must be replaced with double single quotes ('')
  input = input.replace(/'/g, "''")
  // backslashes (\) must be replaced with double backslashes (\\)
  input = input.replace(/\\/g, '\\\\')
  // double quotes (") must be replaced with escaped quotes (\\")
  input = input.replace(/"/g, '\\"')
  return input
}
1169081
def _escapeCharacters(tag):
	""""""
	for i,c in enumerate(tag.contents):
		if type(c) != bs4.element.NavigableString:
			continue
		c.replace_with(_escapeCharSub(r'\\\1', c))
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)
17750
static function InitStaticVars()
	{

		self::$HTML_ENTITIES_TABLE = array();
		foreach (get_html_translation_table(HTML_ENTITIES, ENT_QUOTES) as $char => $entity)
		{
			self::$HTML_ENTITIES_TABLE[$entity] = '&#' . ord($char) . ';';
		}

		self::$SMART_QUOTE_CHARS =
			array(
				"�" => "'",
				"�" => "'",
				"�" => "\"",
				"�" => "\"",
				chr(145) => "'",
				chr(146) => "'",
				chr(147) => "\"",
				chr(148) => "\"",
				chr(151) => "-"
			);

		self::$CONTROL_CODE_CHARS =
			array(
				chr(0) => "&#0;",
				chr(1) => "&#1;",
				chr(2) => "&#2;",
				chr(3) => "&#3;",
				chr(4) => "&#4;",
				chr(5) => "&#5;",
				chr(6) => "&#6;",
				chr(7) => "&#7;",
				chr(8) => "&#8;",
				chr(14) => "&#14;",
				chr(15) => "&#15;",
				chr(16) => "&#16;",
				chr(17) => "&#17;",
				chr(18) => "&#18;",
				chr(19) => "&#19;",
				chr(20) => "&#20;",
				chr(21) => "&#21;",
				chr(22) => "&#22;",
				chr(23) => "&#23;",
				chr(24) => "&#24;",
				chr(25) => "&#25;",
				chr(26) => "&#26;",
				chr(27) => "&#27;",
				chr(28) => "&#28;",
				chr(29) => "&#29;",
				chr(30) => "&#30;",
				chr(31) => "&#31;"
			);

		self::$INVALID_CODE_CHARS = array(
			chr(128) => '&#8364;',
			chr(130) => '&#8218;',
			chr(131) => '&#402;',
			chr(132) => '&#8222;',
			chr(133) => '&#8230;',
			chr(134) => '&#8224;',
			chr(135) => '&#8225;',
			chr(136) => '&#710;',
			chr(137) => '&#8240;',
			chr(138) => '&#352;',
			chr(139) => '&#8249;',
			chr(140) => '&#338;',
			chr(142) => '&#381;',
			chr(145) => '&#8216;',
			chr(146) => '&#8217;',
			chr(147) => '&#8220;',
			chr(148) => '&#8221;',
			chr(149) => '&#8226;',
			chr(150) => '&#8211;',
			chr(151) => '&#8212;',
			chr(152) => '&#732;',
			chr(153) => '&#8482;',
			chr(154) => '&#353;',
			chr(155) => '&#8250;',
			chr(156) => '&#339;',
			chr(158) => '&#382;',
			chr(159) => '&#376;');

		self::$XML_SPECIAL_CHARS = array(
			"&"   =>"&amp;",
			"<"   =>"&lt;"
			,">"  =>"&gt;"
			,"\"" =>"&quot;"
			,"'"  =>"&apos;"
		);

	}
1015809
protected void init(String str) {
	int len = str.length();
	text = new char[len];
	lcText = new char[len];

	for (int i = 0; i < len; i++) {
	    char c = str.charAt(i);
	    text[i] = c;
	    if (c == '\n' || c == '\r' || c == '\t') {
		lcText[i] = ' ';
	    }
	    else lcText[i] = ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')) ? c : Character.toLowerCase(c);
	}
    }
1104644
function escapeStringForJavascript(content) {
  return content.replace(/(['\\])/g, '\\$1')
    .replace(/[\f]/g, "\\f")
    .replace(/[\b]/g, "\\b")
    .replace(/[\n]/g, "\\n")
    .replace(/[\t]/g, "\\t")
    .replace(/[\r]/g, "\\r")
    .replace(/[\u2028]/g, "\\u2028")
    .replace(/[\u2029]/g, "\\u2029");
}
892346
def remove_escapes(self):
        
        chars = []

        i = 0
        while i < len(self.string):
            char = self.string[i]
            if char == "\\":
                i += 1
            else:
                chars.append(char)

            i += 1

        return "".join(chars)
966540
static void escape(Appendable accum, String string, Document.OutputSettings out,
                       boolean inAttribute, boolean normaliseWhite, boolean stripLeadingWhite) throws IOException {

        boolean lastWasWhite = false;
        boolean reachedNonWhite = false;
        final EscapeMode escapeMode = out.escapeMode();
        final CharsetEncoder encoder = out.encoder();
        final CoreCharset coreCharset = out.coreCharset; // init in out.prepareEncoder()
        final int length = string.length();

        int codePoint;
        for (int offset = 0; offset < length; offset += Character.charCount(codePoint)) {
            codePoint = string.codePointAt(offset);

            if (normaliseWhite) {
                if (StringUtil.isWhitespace(codePoint)) {
                    if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite)
                        continue;
                    accum.append(' ');
                    lastWasWhite = true;
                    continue;
                } else {
                    lastWasWhite = false;
                    reachedNonWhite = true;
                }
            }
            // surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]):
            if (codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
                final char c = (char) codePoint;
                // html specific and required escapes:
                switch (c) {
                    case '&':
                        accum.append("&amp;");
                        break;
                    case 0xA0:
                        if (escapeMode != EscapeMode.xhtml)
                            accum.append("&nbsp;");
                        else
                            accum.append("&#xa0;");
                        break;
                    case '<':
                        // escape when in character data or when in a xml attribue val; not needed in html attr val
                        if (!inAttribute || escapeMode == EscapeMode.xhtml)
                            accum.append("&lt;");
                        else
                            accum.append(c);
                        break;
                    case '>':
                        if (!inAttribute)
                            accum.append("&gt;");
                        else
                            accum.append(c);
                        break;
                    case '"':
                        if (inAttribute)
                            accum.append("&quot;");
                        else
                            accum.append(c);
                        break;
                    default:
                        if (canEncode(coreCharset, c, encoder))
                            accum.append(c);
                        else
                            appendEncoded(accum, escapeMode, codePoint);
                }
            } else {
                final String c = new String(Character.toChars(codePoint));
                if (encoder.canEncode(c)) // uses fallback encoder for simplicity
                    accum.append(c);
                else
                    appendEncoded(accum, escapeMode, codePoint);
            }
        }
    }