List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:Main.java
public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; }// w ww .jav a 2 s. c o m char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); }
From source file:Main.java
private static String camelCase2Upper(String s) { String r = ""; boolean u = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); char C = Character.toUpperCase(c); if (Character.isUpperCase(c)) { r = r + (u ? ("_" + C) : C); } else {//from ww w.jav a2s .c o m u = true; r = r + C; } } return r; }
From source file:Main.java
private static String splitCamelToHuman(final String source) { StringBuilder target = new StringBuilder(); boolean isFirstChar = true; for (int i = 0; i < source.length(); i++) { Character ch = source.charAt(i); if (Character.isUpperCase(ch)) { target.append(" "); if (isFirstChar) { target.append(ch);/*w ww . ja v a2 s.c o m*/ isFirstChar = false; } else { target.append(Character.toLowerCase(ch)); } } else { target.append(ch); } } return target.toString(); }
From source file:Main.java
public static String[] splitByCamelCase(String name) { List<String> parts = new ArrayList<String>(); StringBuilder b = new StringBuilder(); for (int i = 0; i < name.length(); i++) { if (i > 0 && Character.isUpperCase(name.charAt(i))) { parts.add(b.toString());/* w w w . ja v a2 s .com*/ b = new StringBuilder(); } b.append(Character.toLowerCase(name.charAt(i))); } parts.add(b.toString()); return parts.toArray(new String[] {}); }
From source file:Main.java
private static String toIdName(String fieldName) { String idName = String.valueOf(Character.toLowerCase(fieldName.charAt(1))); for (int i = 2, length = fieldName.length(); i < length; ++i) { char c = fieldName.charAt(i); if (Character.isUpperCase(c)) { idName = idName + ID_SEPARATOR + Character.toLowerCase(c); } else {// w w w .j ava 2s.com idName += c; } } return idName; }
From source file:Main.java
public static String toConstantFormat(String str) { int n = str.length(); List<Character> list = new ArrayList<Character>(); char c;/*from ww w . j a va 2s.c om*/ for (int i = 0; i < n; i++) { c = str.charAt(i); if (i != 0 && Character.isUpperCase(c)) { list.add('_'); } list.add(Character.toUpperCase(c)); } StringBuffer buffer = new StringBuffer(); for (Character character : list) { buffer.append(character); } return buffer.toString(); }
From source file:Main.java
/** convert given "directiveName" to "directive-name" */ private static String getDirectiveNameAsHtmlAttribute(String directiveName) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < directiveName.length(); i++) { char ch = directiveName.charAt(i); if (Character.isUpperCase(ch)) { sb.append('-'); ch = Character.toLowerCase(ch); }//from w w w . j ava 2s . c om sb.append(ch); } return sb.toString(); }
From source file:Main.java
/** * @param str str//ww w. j a va 2 s .com * @return String */ public static String capitalizeFirstLetter(String str) { if (isEmpty(str)) { return str; } char c = str.charAt(0); return (!Character.isLetter(c) || Character.isUpperCase(c)) ? str : new StringBuilder(str.length()).append(Character.toUpperCase(c)).append(str.substring(1)) .toString(); }
From source file:Main.java
private static String addSpaceIfRequired(String value, int index) { if (index == 0) return VOID_STRING; char precedingChar = value.charAt(index - 1); char thisChar = value.charAt(index); if (Character.isLowerCase(precedingChar) && Character.isUpperCase(thisChar) || Character.isLetter(precedingChar) && Character.isDigit(thisChar) || Character.isDigit(precedingChar) && Character.isLetter(thisChar)) { return SPACE; }//from ww w . jav a 2 s .c o m if (index + 1 == value.length()) return VOID_STRING; char nextChar = value.charAt(index + 1); if (Character.isUpperCase(precedingChar) && Character.isUpperCase(thisChar) && Character.isLowerCase(nextChar)) { return SPACE; } return VOID_STRING; }
From source file:MainClass.java
static String capitalize(String s) throws NullPointerException, AlreadyCapitalizedException { if (s == null) { throw new NullPointerException("Your passed a null argument"); }//from ww w . j a v a2 s. com Character firstChar = s.charAt(0); if (Character.isUpperCase(firstChar)) { throw new AlreadyCapitalizedException(); } String theRest = s.substring(1); return firstChar.toString().toUpperCase() + theRest; }