List of utility methods to do Unicode
int | unicodeCount(String sStr) unicode Count if (sStr == null || sStr.equals("")) { return 0; int count = 0; for (int i = 0; i < sStr.length(); i++) { if ((int) sStr.charAt(i) > 255) { count++; return count; |
String | unicodeEncode(String s) unicode encoding (for verbose mode) StringBuilder buf = new StringBuilder(); for (int i = 0; i < s.length(); ++i) { char ch = s.charAt(i); if (ch >= '\u0080') { String st = Integer.toHexString(0x10000 + (int) ch); while (st.length() < 4) st = "0" + st; buf.append("\\u").append(st.subSequence(1, 5)); ... |
String | unicodeHTMLEscape(final String s) Perform Unicode Escape on Specified String. 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("&#"); hexChars[0] = hexChar[(c >> 12) & 0xF]; hexChars[1] = hexChar[(c >> 8) & 0xF]; ... |
int | unicodePreservingIndex(String str, int index) Normalizes index such that it respects Unicode character boundaries in str . if (index > 0 && index < str.length()) { if (Character.isHighSurrogate(str.charAt(index - 1)) && Character.isLowSurrogate(str.charAt(index))) { return index - 1; return index; |
String | unicodePreservingSubstring(String str, int begin, int end) Returns a substring of str that respects Unicode character boundaries. return str.substring(unicodePreservingIndex(str, begin), unicodePreservingIndex(str, end));
|
String | unicodeToChar(char[] unicode) unicode To Char return String.valueOf((char) Integer.parseInt(String.valueOf(unicode), 16)); |
String | unicodeToHTMLUnicodeEntity(final String text) unicode To HTML Unicode Entity StringBuilder result = null; int intValue; char myChar; for (int i = 0; i < text.length(); ++i) { myChar = text.charAt(i); intValue = text.charAt(i); if (intValue < 32 || intValue > 126) { if (result == null) { ... |
String | unicodeTrim(String s) unicode Trim final int length = s.length(); if (length == 0) return s; int start = 0; while (start < length) { char c = s.charAt(start); if (c == ' ' || c == '\n') { start += 1; ... |