Here you can find the source of unicodeHTMLEscape(final String s)
Parameter | Description |
---|---|
s | a parameter |
public static String unicodeHTMLEscape(final String s)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j a v a 2s. c o m*/ * Hexadecimal Character Array. */ static final char[] hexChar = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; /** * Perform Unicode Escape on Specified String. * * @param s * @return String Escaped */ public static String unicodeHTMLEscape(final String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); char[] hexChars = new char[4]; if ((c >> 7) > 0) { sb.append("&#"); // Begin encoding of character. hexChars[0] = hexChar[(c >> 12) & 0xF]; // append the hex character for the left-most 4-bits hexChars[1] = hexChar[(c >> 8) & 0xF]; // hex for the second group of 4-bits from the left hexChars[2] = hexChar[(c >> 4) & 0xF]; // hex for the third group hexChars[3] = hexChar[c & 0xF]; // hex for the last group, e.g., the right most 4-bits String aString = "" + hexChars[0] + "" + hexChars[1] + "" + hexChars[2] + "" + hexChars[3]; // Make Hex String into decimal Number. Integer a = Integer.valueOf(aString, 16); sb.append(a); sb.append(";"); } else { sb.append(c); } } return sb.toString(); } }