Given a string, escape all special html characters and
return the result.

@param s The string to check.
@return the original string with all of the HTML characters escaped.
199014
private static String escapeHtmlChars(String s) {
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            switch (ch) {
                // only start building a new string if we need to
                case '<': case '>': case '&':
                    StringBuilder sb = new StringBuilder(s.substring(0, i));
                    for ( ; i < s.length(); i++) {
                        ch = s.charAt(i);
                        switch (ch) {
                            case '<': sb.append("&lt;");  break;
                            case '>': sb.append("&gt;");  break;
                            case '&': sb.append("&amp;"); break;
                            default:  sb.append(ch);      break;
                        }
                    }
                    return sb.toString();
            }
        }
        return s;
    }
1317364
public static String encodeString(final String s) {
		if (s != null) {
			final StringBuilder sb = new StringBuilder(s.length() + s.length() / 4);
			encodeString(sb, s);
			return sb.toString();
		}
		return "";
	}
770422
public static String convertText(String s) {
        StringCharacterIterator stringcharacteriterator = new StringCharacterIterator(s);
        StringBuffer stringbuffer = new StringBuffer();
        int ai[] = new int[s.length()];
        int i = 0;
        int j = 0;
        for(char c = stringcharacteriterator.first(); c != '\uFFFF'; c = stringcharacteriterator.next())
            if(c == '%')
            {
                c = stringcharacteriterator.next();
                if(c != '%')
                {
                    stringbuffer.append('%');
                    c = stringcharacteriterator.previous();
                } else
                {
                    c = stringcharacteriterator.next();
                    switch(c)
                    {
                    case 37: // '%'
                        stringbuffer.append('%');
                        break;

                    case 80: // 'P'
                    case 112: // 'p'
                        stringbuffer.append('\361');
                        break;

                    case 67: // 'C'
                    case 99: // 'c'
                        stringbuffer.append('\355');
                        break;

                    case 68: // 'D'
                    case 100: // 'd'
                        stringbuffer.append('\u00b0');
                        break;

                    case 85: // 'U'
                    case 117: // 'u'
                        ai[stringbuffer.length()] ^= 1;
                        i++;
                        break;

                    case 79: // 'O'
                    case 111: // 'o'
                        ai[stringbuffer.length()] ^= 2;
                        j++;
                        break;

                    default:
                        if(c >= '0' && c <= '9')
                        {
                            int k = 3;
                            char c1 = (char)(c - 48);
                            for(c = stringcharacteriterator.next(); c >= '0' && c <= '9' && --k > 0; c = stringcharacteriterator.next())
                                c1 = (char)(10 * c1 + (c - 48));

                            stringbuffer.append(c1);
                        }
                        c = stringcharacteriterator.previous();
                        break;
                    }
                }
            } else
            if(c == '^')
            {
                c = stringcharacteriterator.next();
                if(c == ' ')
                    stringbuffer.append('^');
            } else
            {
                stringbuffer.append(c);
            }
        s = Unicode.char2DOS437(stringbuffer, 2, '?');

		String ss = s;
		return ss;
	}
}
107476
public static String normalize(final String s) {
        if (s == null || s.trim().isEmpty()) {
            return "unspecific";
        }
        return s.replace(':', '/')
                .replace('=', '-')
                .replace(',', '|')
                .replace("\"", "")
                .replace('#', '-');
    }
860261
static CharSequence decode(final CharSequence s) {
    if (!contains(s, '%')) {
      return s.toString();
    }
    return decode0(s);
  }
57371
public static String escape(String str) {
		if (StrUtil.isEmpty(str)) {
			return str;
		}

		final int len = str.length();
		final StringBuilder builder = new StringBuilder(len);
		char c;
		for (int i = 0; i < len; i++) {
			c = str.charAt(i);
			builder.append(escape(c));
		}
		return builder.toString();
	}
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();
    }
1280729
public static byte[] decode(String s)
  {
	  ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int len = s.length();
 	  
	  boolean toggle = false;
	  int keep = 0;

    for (int i = 0; i < len; i++) {
      char ch = s.charAt(i);
 	    int n = ALPHABET.indexOf(Character.toLowerCase(ch));
	    if (n == -1) {
		    throw new 
		      IllegalArgumentException(s+" is not properly encoded");
	    }

 	    toggle = !toggle;

 	    if (toggle) {
		    keep = n;
	    } else {
		    baos.write((keep << 4) | n);
 	    }
 	  }
	  return baos.toByteArray();
  }
452572
public static String escapeAssertion(String s) {
        //Replace the first dot, because the string doesn't start with "m="
        // and is not covered by the regex.
        if (s.startsWith("r") || s.startsWith("p")) {
            s = s.replaceFirst("\\.", "_");
        }
        String regex = "(\\|| |=|\\)|\\(|&|<|>|,|\\+|-|!|\\*|\\/)(r|p)\\.";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(s);
        StringBuffer sb = new StringBuffer();

        while (m.find()) {
            m.appendReplacement(sb, m.group().replace(".", "_") );
        }
        
        m.appendTail(sb);
        return sb.toString();
    }
293687
private static String stringify(final String s) {
    final StringBuilder buf = new StringBuilder(1 + s.length() + 1);
    buf.append('"');
    HttpQuery.escapeJson(s, buf);  // Abusing this function gets the job done.
    buf.append('"');
    return buf.toString();
  }
967984
public static String escapeAttributeName(String s) {
        s = cleanWS(s);
        s = replaceAll(s, BackSlashPtn, EscBackSlash);
        s = replaceAll(s, EqualPtn, EscEqual);
        return s;
    }
1118204
public static String wrap(String s) {
		StringBuilder sb = new StringBuilder();

		sb.append("(");
		sb.append(s);
		sb.append(")");

		return sb.toString();
	}
233690
public static String asciiToLowerCase(String s)
    {
        char[] c = null;
        int i=s.length();

        // look for first conversion
        while (i-->0)
        {
            char c1=s.charAt(i);
            if (c1<=127)
            {
                char c2=lowercases[c1];
                if (c1!=c2)
                {
                    c=s.toCharArray();
                    c[i]=c2;
                    break;
                }
            }
        }

        while (i-->0)
        {
            if(c[i]<=127)
                c[i] = lowercases[c[i]];
        }
        
        return c==null?s:new String(c);
    }
605364
public static String normalizeCharset(String s) {
        String n = CHARSETS.get(s);
        return (n == null) ? s : n;
    }
1038613
public static String escapeAttributeValue(String s) {
        s = cleanWS(s);
        s = replaceAll(s, BackSlashPtn, EscBackSlash);
        s = replaceAll(s, SemicolonPtn, EscSemicolon);
        s = replaceAll(s, RParenPtn, EscRParen);
        return s;
    }
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();
	}
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