List of usage examples for java.lang String codePointAt
public int codePointAt(int index)
From source file:bfile.util.StringUtils.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>//from w w w .j a va 2s. c om * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link org.apache.commons.lang3.text.WordUtils#swapCase(String)}. * A {@code null} input String returns {@code null}.</p> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in org.apache.commons.lang3.text.WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, {@code null} if null String input */ public static String swapCase(final String str) { if (StringUtils.isEmpty(str)) { return str; } final int strLen = str.length(); int newCodePoints[] = new int[strLen]; // cannot be longer than the char array int outOffset = 0; for (int i = 0; i < strLen;) { final int oldCodepoint = str.codePointAt(i); final int newCodePoint; if (Character.isUpperCase(oldCodepoint)) { newCodePoint = Character.toLowerCase(oldCodepoint); } else if (Character.isTitleCase(oldCodepoint)) { newCodePoint = Character.toLowerCase(oldCodepoint); } else if (Character.isLowerCase(oldCodepoint)) { newCodePoint = Character.toUpperCase(oldCodepoint); } else { newCodePoint = oldCodepoint; } newCodePoints[outOffset++] = newCodePoint; i += Character.charCount(newCodePoint); } return new String(newCodePoints, 0, outOffset); }
From source file:StreamFlusher.java
public Object visit(ASTnet_explode_func_call node, Object data) { // just #^__explode(regexp) built-in // take a two-state, one arc acceptor, get the label // on the one arc // (an int, typically mapping to a multichar name), // get the print name, // make a new one-path network for the exploded // string of characters in that name // there should be just one daughter, acceptor, // one string (non-empty), two states, one arc node.jjtGetChild(0).jjtAccept(this, data); Fst fst = (Fst) stack.pop();/*from w ww . j a v a 2s.c o m*/ // get the single arc label int label = lib.GetSingleArcLabel(fst); // get the print name of the symbol // (typically a multichar symbol name) String str = symmap.getsym(label); // KRB // the str will be composed of BMP Unicode characters // (keep an eye on this--it // depends on what is allowed in a multichar symbol) int len = str.length(); // create an array of ints (code point values) int[] cpvArray = new int[len]; for (int index = 0; index < len; index++) { int cpv = str.codePointAt(index); symmap.putsym(String.valueOf((char) cpv)); cpvArray[index] = cpv; } Fst resultFst = lib.FstFromCpvArray(cpvArray); stack.push(resultFst); return data; }
From source file:StreamFlusher.java
public Object visit(ASTnet_to_string_func_call node, Object data) { // convert a number (Long or Float) to a string // just $^__toString(numexp) built-in // should be just one daughter: arg_list with one numexp node.jjtGetChild(0).jjtAccept(this, data); // leaves a Long or Double object on the stack Object obj = stack.pop();//from w w w .ja v a 2 s.c om String str; // produce either Long or Double, according to the input if (obj instanceof Long) { str = Long.toString(((Long) obj).longValue()); } else { str = Double.toString(((Double) obj).doubleValue()); } // Because all digits in a number string are in the BMP, // this str will be composed of BMP Unicode characters // convert to an array of int int len = str.length(); int[] cpvArray = new int[len]; for (int index = 0; index < len; index++) { int cpv = str.codePointAt(index); symmap.putsym(String.valueOf((char) cpv)); cpvArray[index] = cpv; } Fst resultFst = lib.FstFromCpvArray(cpvArray); stack.push(resultFst); return data; }