List of usage examples for java.lang Character isTitleCase
public static boolean isTitleCase(int codePoint)
From source file:com.clark.func.Functions.java
/** * <p>/* w ww . j a va 2s . c o m*/ * Swaps the case of a String changing upper and title case to lower case, * and lower case to upper case. * </p> * * <ul> * <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</code> input String returns <code>null</code>. * </p> * * <pre> * swapCase(null) = null * swapCase("") = "" * 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</code> if null String input */ public static String swapCase(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } StringBuilder buffer = new StringBuilder(strLen); char ch = 0; for (int i = 0; i < strLen; i++) { ch = str.charAt(i); if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { ch = Character.toUpperCase(ch); } buffer.append(ch); } return buffer.toString(); }
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 v a 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:org.ballerinalang.composer.service.workspace.swagger.SwaggerConverterUtils.java
public static String capitalize(String str) { int strLen;//from w ww . j a va2 s .c o m if (str != null && (strLen = str.length()) != 0) { char firstChar = str.charAt(0); return Character.isTitleCase(firstChar) ? str : (new StringBuilder(strLen)).append(Character.toTitleCase(firstChar)).append(str.substring(1)) .toString(); } else { return str; } }