List of usage examples for java.lang String codePointAt
public int codePointAt(int index)
From source file:hm.binkley.util.ServiceBinder.java
private static boolean skip(final String s) { if (null == s) return true; final int len = s.length(); if (0 == len) return true; for (int i = 0; i < len;) { final int cp = s.codePointAt(i); if (!isWhitespace(cp)) return false; i += charCount(cp);/*from w w w. ja v a 2 s. co m*/ } return true; }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with no whitespace at all * @param arg string//from w w w. ja v a 2s . c om * @return string with no whitespace */ public static String noWhiteSpace(String arg) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arg.length(); i++) { int c = arg.codePointAt(i); if (!Character.isWhitespace(c)) { sb.appendCodePoint(c); } } return sb.toString(); }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with no whitespace at all * @param arg string/*from www . ja v a2 s .c o m*/ * @return string with no whitespace */ public static String justLettersOrDigits(String arg) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arg.length(); i++) { int c = arg.codePointAt(i); if (Character.isLetterOrDigit(c)) { sb.appendCodePoint(c); } } return sb.toString(); }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with only letters// w w w . j av a2 s .c om * @param arg string * @return string with only letters, no punct, space, digits, etc. */ public static String justLetters(String arg) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arg.length(); i++) { int c = arg.codePointAt(i); if (Character.isLetter(c)) { sb.appendCodePoint(c); } } return sb.toString(); }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with only digits/* ww w.ja va 2 s . c o m*/ * @param arg string * @return string with only digits */ public static String justDigits(String arg) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < arg.length(); i++) { int c = arg.codePointAt(i); if (Character.isDigit(c)) { sb.appendCodePoint(c); } } return sb.toString(); }
From source file:org.exoplatform.cms.common.TransformHTML.java
public static String enCodeViewSignature(String s) { if (s != null && s.trim().length() > 0) { // replace enter key to <br/> tag html StringBuffer buffer = new StringBuffer(); for (int j = 0; j < s.trim().length(); j++) { if (s.codePointAt(j) == 10) { buffer.append("<br/>"); } else { buffer.append(s.charAt(j)); }//from ww w .j a v a 2s . c om } s = buffer.toString(); } else s = EMPTY_STR; return s; }
From source file:com.predic8.membrane.core.interceptor.IndexInterceptor.java
static String fullfillRegexp(String regex) { StringBuilder sb = new StringBuilder(); int p = 0, groupLevel = 0; WHILE: while (p < regex.length()) { int c = regex.codePointAt(p++); switch (c) { case '\\': if (p == regex.length()) return null; // illegal c = regex.codePointAt(p++);//from w w w. j a va 2 s . c o m if (Character.isDigit(c)) return null; // backreferences are not supported if (c == 'Q') { while (true) { if (p == regex.length()) return null; // 'end of regex' within quote c = regex.codePointAt(p++); if (c == '\\') { if (p == regex.length()) return null; // 'end of regex' within quote c = regex.codePointAt(p++); if (c == 'E') break; sb.append('\\'); } sb.appendCodePoint(c); } break; } if (c == 'E') { return null; // 'end of quote' without begin } sb.appendCodePoint(c); break; case '[': case '?': case '*': case '+': case '{': return null; // meaningful characters we do not unterstand case '(': groupLevel++; break; case ')': if (groupLevel == 0) return null; // unbalanced ')' else groupLevel--; break; case '|': if (groupLevel == 0) { break WHILE; } W2: while (true) { if (++p == regex.length()) return null; // unbalanced ')' switch (regex.charAt(p)) { case ')': break W2; case '[': case '?': case '*': case '+': case '{': return null; // meaningful characters we do not unterstand case '\\': return null; // TODO: \) \Q..\E } } groupLevel--; p++; break; case '^': if (p == 1) break; return null; case '$': if (p == regex.length() || regex.codePointAt(p) == '|') break; return null; case '.': int q; if (p != regex.length() && isQuantifier(q = regex.codePointAt(p))) { if (++p != regex.length() && isModifier(regex.codePointAt(p))) p++; if (q == '+') sb.append('a'); } else { sb.append('a'); } break; default: sb.appendCodePoint(c); break; } } if (groupLevel > 0) return null; return sb.toString(); }
From source file:com.marklogic.mapreduce.utilities.InternalUtilities.java
public static String unparse(String s) { int len = s.length(); StringBuilder buf = new StringBuilder(len * 2); for (int cp, i = 0; i < s.length(); i += Character.charCount(cp)) { cp = s.codePointAt(i); // iterate through the codepoints in the string if ((cp >= 0x20) && (cp < 0x80)) { switch (cp) { case '"': buf.append("""); break; case '&': buf.append("&"); break; default: buf.append(s.charAt(i)); }//from w w w. j a v a 2 s. c om } else { buf.append("&#x"); buf.append(Long.toString(cp, 16)); buf.append(';'); } } return buf.toString(); }
From source file:password.pwm.util.StringUtil.java
public static int[] toCodePointArray(String str) { if (str != null) { int len = str.length(); int[] acp = new int[str.codePointCount(0, len)]; for (int i = 0, j = 0; i < len; i = str.offsetByCodePoints(i, 1)) { acp[j++] = str.codePointAt(i); }//from w w w . ja v a 2 s . c om return acp; } return new int[0]; }
From source file:Main.java
/** * This method ensures that the output String has only valid XML unicode * characters as specified by the XML 1.0 standard. For reference, please * see//from ww w .j a v a 2s .c o m * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the * standard</a>. This method will return an empty String if the input is * null or empty. * * @param in The String whose non-valid characters we want to remove. * @return The in String, stripped of non-valid characters. */ public static String cleanInvalidXmlChars(String text) { if (null == text || text.isEmpty()) { return text; } final int len = text.length(); char current = 0; int codePoint = 0; StringBuilder sb = new StringBuilder(); for (int i = 0; i < len; i++) { current = text.charAt(i); boolean surrogate = false; if (Character.isHighSurrogate(current) && i + 1 < len && Character.isLowSurrogate(text.charAt(i + 1))) { surrogate = true; codePoint = text.codePointAt(i++); } else { codePoint = current; } if ((codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { sb.append(current); if (surrogate) { sb.append(text.charAt(i)); } } else { // // Invalid Char at index transformed into hex //System.err.println("Index=["+ i +"] Char=["+ String.format("%04x", (int)text.charAt(i)) +"] CodePoint=[" + codePoint + "]"); //sb.append("hex"+String.format("%04x", (int)text.charAt(i))); } } return sb.toString(); }