Java String Quote quoteHTML(String string)

Here you can find the source of quoteHTML(String string)

Description

quote HTML

License

Open Source License

Declaration

public static String quoteHTML(String string) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String quoteHTML(String string) {

        if (string == null || string.length() == 0) {
            return "{}";
        }//from   w  w  w .  j  a  v a 2 s  .  com

        char c = 0;
        int i;
        int len = string.length();
        StringBuilder sb = new StringBuilder(len + 4);
        String t;

        for (i = 0; i < len; i += 1) {
            c = string.charAt(i);
            switch (c) {
            case '\\':
                sb.append("REPLACEKEY");
                break;
            default:
                if (c < ' ') {
                    t = "000" + Integer.toHexString(c);
                    sb.append("\\u" + t.substring(t.length() - 4));
                } else {
                    sb.append(c);
                }
            }
        }
        String result = sb.toString().replaceAll("REPLACEKEYn", "<br />");
        return result;
    }
}

Related

  1. quoteForRegEx(String input)
  2. quoteForXML(String from)
  3. quoteHost(final String hostname)
  4. quoteHtml(final String s)
  5. quoteHtml(String s)
  6. quoteHtmlContent(String x)
  7. quoteIdentifier(String identifier)
  8. quoteIdentifier(String identifier, boolean isPedantic)
  9. quoteIdentifier(String identifier, boolean isPedantic)