Escapes special symbols in a string.  For example '<' becomes '&lt;'
173237
public static String escapeHtml(String s)
  {
    if (s == null)
      return null;

    StringBuilder cb = new StringBuilder();
    int lineCharacter = 0;
    boolean startsWithSpace = false;
    
    for (int i = 0; i < s.length(); i++) {
      char ch = s.charAt(i);

      lineCharacter++;
      
      if (ch == '<')
        cb.append("&lt;");
      else if (ch == '&')
        cb.append("&amp;");
      else if (ch == '\n' || ch == '\r') {
        lineCharacter = 0;
        cb.append(ch);
        startsWithSpace = false;
      }
      else if (lineCharacter > 70 && ch == ' ' && ! startsWithSpace) {
        lineCharacter = 0;
        cb.append('\n');
        for (; i + 1 < s.length() && s.charAt(i + 1) == ' '; i++) {
        }
      }
      else if (lineCharacter == 1 && (ch == ' ' || ch == '\t')) {
        cb.append((char) ch);
        startsWithSpace = true;
      }
      else
        cb.append(ch);
    }

    return cb.toString();
  }
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
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))
1307671
public static String escape(CharSequence s) {
		StringBuilder str = new StringBuilder();
		int len = s.length();
		for (int i = 0; i < len; ++i) {
			char c = s.charAt(i);
			if (c == '&') str.append("&amp;");
			else if (c == '"') str.append("&quot;");
			else if (c == '\'') str.append("&apos;");
			else if (c == '>') str.append("&gt;");
			else if (c == '<') str.append("&lt;");
			else if (c < 32) str.append("&#").append((int)c).append(';');
			else str.append(c);
		}
		return str.toString();
	}
478362
function _escapeHtml (input) {
  return String(input)
   .replace(/&/g, '&amp;')
   .replace(/</g, '&lt;')
   .replace(/>/g, '&gt;')
   .replace(/"/g, '&quot;')
   .replace(/'/g, '&#039;');
 }
778954
function HTMLEscape(original) {
  return original.replace(/&/g, '&amp;')
                 .replace(/</g, '&lt;')
                 .replace(/>/g, '&gt;')
                 .replace(/"/g, '&quot;')
                 .replace(/'/g, '&#39;');
}
315802
function escapeString(str) {

    if(str === undefined) {
        throw new Error('\'str\' is required');
    }

    if(str === null) {
        throw new Error('\'str\' must not be null');
    }

    if(typeof str !== 'string') {
        throw new Error('\'str\' must be a string');
    }

    /*
     * Need to escape backslashes (\) first because escaping ' and " will also 
     * add a \, which interferes with \ escaping.
     */
    var escaped_str = str;
    // regex replace all \ to \\
    escaped_str = escaped_str.replace(/\\/g, '\\\\');
    // regex replace all ' to \'
    escaped_str = escaped_str.replace(/'/g, '\\\'');
    // regex replace all " to \"
    escaped_str = escaped_str.replace(/"/g, '\\"');

    return escaped_str;

}
1247661
function escapeFormat(t) {
  return (
    t
      // Inline single underscore.
      .replace(/([^_])_([^_])/g, '$1 $2')
      // Leading or trailing underscore.
      .replace(/([^_])_$/, '$1 ')
      .replace(/^_([^_])/, ' $1')
      // Double underscore and double dash.
      .replace(/__/g, '_')
      .replace(/--/g, '-')
  )
}
1100026
function escape(str) {
  var re = /\{([^{}]*?)}|\(([^()]*?)\)|\[([^\[\]]*?)\]/g;
  return str.replace(re, function (outter, braces, parens, brackets) {
    var inner = braces || parens || brackets;
    if (!inner) { return outter; }
    return outter.split(inner).join(esc(inner));
  });
}
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
828574
protected String escapeXmlSpecialCharacters(String url) {
		// https://stackoverflow.com/questions/1091945/what-characters-do-i-need-to-escape-in-xml-documents
		return url
				.replace("&", "&amp;") // must be escaped first!!!
				.replace("\"", "&quot;")
				.replace("'", "&apos;")
				.replace("<", "&lt;")
				.replace(">", "&gt;");
	}
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();
	}
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();
    }
1095837
private static String escape(String string) {
        StringBuilder sb = new StringBuilder((int) (string.length() * 1.1));
        for (int i = 0; i < string.length(); i++) {
            char c = string.charAt(i);
            switch (c) {
            case ',':
                sb.append("=2C");
                break;
            case '=':
                sb.append("=3D");
                break;
            default:
                sb.append(c);
                break;
            }
        }
        return sb.toString();
    }
931535
public static String encode(String str) {
    if (str == null) {
      return "";
    }

    return ESCAPER.escape(str)
      .replaceAll("\\!", "%21")
      .replaceAll("\\$", "%24")
      .replaceAll("\\&", "%26")
      .replaceAll("\\'", "%27")
      .replaceAll("\\(", "%28")
      .replaceAll("\\)", "%29")
      .replaceAll("\\*", "%2A")
      .replaceAll("\\+", "%2B")
      .replaceAll("\\,", "%2C")
      .replaceAll("\\/", "%2F")
      .replaceAll("\\:", "%3A")
      .replaceAll("\\;", "%3B")
      .replaceAll("\\=", "%3D")
      .replaceAll("\\@", "%40")
      .replaceAll("\\[", "%5B")
      .replaceAll("\\]", "%5D");
  }
1200211
def escape( text, newline=False ):
    """"""

    if isinstance( text, basestring ):
        if '&' in text:
            text = text.replace( '&', '&amp;' )
        if '>' in text:
            text = text.replace( '>', '&gt;' )
        if '<' in text:
            text = text.replace( '<', '&lt;' )
        if '\"' in text:
            text = text.replace( '\"', '&quot;' )
        if '\'' in text:
            text = text.replace( '\'', '&quot;' )
        if newline:
            if '\n' in text:
                text = text.replace( '\n', '<br>' )

    return text
1252442
def xml_encode(string):
    
    string = string.replace("&", "&amp;")
    string = string.replace("<", "&lt;")
    string = string.replace(">", "&gt;")
    string = string.replace("\"","&quot;")
    string = string.replace(SLASH, "/")
    return string