List of usage examples for java.lang StringBuilder appendCodePoint
@Override public StringBuilder appendCodePoint(int codePoint)
From source file:Main.java
public static void main(String[] arg) { StringBuilder buffer = new StringBuilder("from java2s.com"); buffer.appendCodePoint(66); System.out.println(buffer);/* w w w . j ava 2s . c om*/ }
From source file:Main.java
public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.appendCodePoint(1064124); }//from ww w . jav a2 s.c o m Charset cs = StandardCharsets.UTF_8; System.out.println(bytesRequiredToEncode(new String(sb), cs)); System.out.println(new String(sb).getBytes(cs).length); }
From source file:Main.java
static String init() { StringBuilder sb = new StringBuilder(); sb.appendCodePoint(CODE_POINT); return sb.toString(); }
From source file:Main.java
public static String removeXMLInvalidChars(String str) { StringBuilder sb = new StringBuilder(str.length()); for (int c, i = 0; i < str.length(); i += Character.charCount(c)) { c = str.codePointAt(i);/* w w w. j ava 2 s . co m*/ if (!isValidXMLChar(c)) { c = ' '; } sb.appendCodePoint(c); } return sb.toString(); }
From source file:Main.java
public static final String filterUCS4(String str) { if (TextUtils.isEmpty(str)) { return str; }/*from www . j ava 2 s . com*/ if (str.codePointCount(0, str.length()) == str.length()) { return str; } StringBuilder sb = new StringBuilder(); int index = 0; while (index < str.length()) { int codePoint = str.codePointAt(index); index += Character.charCount(codePoint); if (Character.isSupplementaryCodePoint(codePoint)) { continue; } sb.appendCodePoint(codePoint); } return sb.toString(); }
From source file:org.renjin.primitives.io.connections.Connections.java
@Internal public static String readChar(@Current Context context, SEXP connIndex, int nchars, @Recycle(false) boolean useBytes) throws IOException { Connection conn = getConnection(context, connIndex); if (useBytes) { byte[] bytes = new byte[nchars]; DataInputStream dis = new DataInputStream(conn.getInputStream()); dis.readFully(bytes);//from ww w. j a va 2s . c o m return new String(bytes, Charsets.UTF_8); } else { // it's not clear to me whether the read(char[]) methods are // safe to use with unicode... Reader in = conn.getReader(); StringBuilder result = new StringBuilder(); for (int i = 0; i != nchars; ++i) { result.appendCodePoint(in.read()); } return result.toString(); } }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with only digits//from ww w . j a v a 2s . 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:com.pfarrell.utils.misc.TextTools.java
/** * make a string with only letters/*from w ww.j a v a 2 s.com*/ * @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:org.marketcetera.util.misc.RandomStrings.java
/** * Returns a randomly generated string of the given length whose * characters are all Unicode code points; in addition, the first * character (if any) is always a letter, the second (if any) is * always a digit, and the rest (if any) are either letters or * digits.// w ww . ja v a2 s.co m * * @param len The length (in code points). * * @return The string. */ public static String genStrId(int len) { if (len <= 0) { return org.apache.commons.lang.StringUtils.EMPTY; } StringBuilder builder = new StringBuilder(); builder.appendCodePoint(genUCPLetter()); if (len == 1) { return builder.toString(); } builder.appendCodePoint(genUCPDigit()); if (len == 2) { return builder.toString(); } builder.append(genStrAlNum(len - 2)); return builder.toString(); }
From source file:com.pfarrell.utils.misc.TextTools.java
/** * make a string with no whitespace at all * @param arg string/* ww w.j a v a 2s . c o m*/ * @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(); }