List of usage examples for java.lang Character toLowerCase
public static int toLowerCase(int codePoint)
From source file:com.rabbitframework.commons.utils.StringUtils.java
/** * _,-,@,$,#,' ',/,&?//from w ww.j av a 2s .com * <p/> * :hello_world ?helloWorld * * @param inputString * @param firstCharacterUppercase * ?? * @return */ public static String toCamelCase(String inputString, boolean firstCharacterUppercase) { StringBuilder sb = new StringBuilder(); boolean nextUpperCase = false; for (int i = 0; i < inputString.length(); i++) { char c = inputString.charAt(i); switch (c) { case '_': case '-': case '@': case '$': case '#': case ' ': case '/': case '&': if (sb.length() > 0) { nextUpperCase = true; } break; default: if (nextUpperCase) { sb.append(Character.toUpperCase(c)); nextUpperCase = false; } else { sb.append(Character.toLowerCase(c)); } break; } } if (firstCharacterUppercase) { sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); } return sb.toString(); }
From source file:de.aschoerk.javaconv.RustDumpVisitor.java
private String toSnakeIfNecessary(String n) { if (namesMap.containsKey(n)) { n = namesMap.get(n);/*from w w w . ja v a 2 s . c om*/ } String name = n; if (Character.isLowerCase(name.charAt(0))) { StringBuilder sb = new StringBuilder(); for (Character c : name.toCharArray()) { if (Character.isUpperCase(c)) { sb.append("_").append(Character.toLowerCase(c)); } else { sb.append(c); } } return sb.toString(); } return n; }
From source file:com.fengduo.bee.commons.util.StringUtils.java
/** * ??//from ww w . j ava 2 s .c o m * * @return toCamelCase("hello_world") == "helloWorld" toCapitalizeCamelCase("hello_world") == "HelloWorld" * toUnderScoreCase("helloWorld") = "hello_world" */ public static String toUnderScoreCase(String s) { if (s == null) { return null; } StringBuilder sb = new StringBuilder(); boolean upperCase = false; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); boolean nextUpperCase = true; if (i < (s.length() - 1)) { nextUpperCase = Character.isUpperCase(s.charAt(i + 1)); } if ((i > 0) && Character.isUpperCase(c)) { if (!upperCase || !nextUpperCase) { sb.append(SEPARATOR); } upperCase = true; } else { upperCase = false; } sb.append(Character.toLowerCase(c)); } return sb.toString(); }
From source file:org.apache.maven.doxia.tools.DefaultSiteTool.java
private static String getRelativeFilePath(final String oldPath, final String newPath) { // normalize the path delimiters String fromPath = new File(oldPath).getPath(); String toPath = new File(newPath).getPath(); // strip any leading slashes if its a windows path if (toPath.matches("^\\[a-zA-Z]:")) { toPath = toPath.substring(1);/*from w w w .j a v a2 s. c o m*/ } if (fromPath.matches("^\\[a-zA-Z]:")) { fromPath = fromPath.substring(1); } // lowercase windows drive letters. if (fromPath.startsWith(":", 1)) { fromPath = Character.toLowerCase(fromPath.charAt(0)) + fromPath.substring(1); } if (toPath.startsWith(":", 1)) { toPath = Character.toLowerCase(toPath.charAt(0)) + toPath.substring(1); } // check for the presence of windows drives. No relative way of // traversing from one to the other. if ((toPath.startsWith(":", 1) && fromPath.startsWith(":", 1)) && (!toPath.substring(0, 1).equals(fromPath.substring(0, 1)))) { // they both have drive path element but they don't match, no // relative path return null; } if ((toPath.startsWith(":", 1) && !fromPath.startsWith(":", 1)) || (!toPath.startsWith(":", 1) && fromPath.startsWith(":", 1))) { // one has a drive path element and the other doesn't, no relative // path. return null; } final String relativePath = buildRelativePath(toPath, fromPath, File.separatorChar); return relativePath.toString(); }
From source file:com.netspective.sparx.util.xml.XmlSource.java
/** * Given a text string, return a string that would be suitable for that string to be used * as a Java identifier (as a variable or method name). Depending upon whether ucaseInitial * is set, the string starts out with a lowercase or uppercase letter. Then, the rule is * to convert all periods into underscores and title case any words separated by * underscores. This has the effect of removing all underscores and creating mixed case * words. For example, Person_Address becomes personAddress or PersonAddress depending upon * whether ucaseInitial is set to true or false. Person.Address would become Person_Address. *//*from www . ja va2 s .c o m*/ public static String xmlTextToJavaIdentifier(String xml, boolean ucaseInitial) { if (xml == null || xml.length() == 0) return xml; StringBuffer identifier = new StringBuffer(); char ch = xml.charAt(0); identifier.append(ucaseInitial ? Character.toUpperCase(ch) : Character.toLowerCase(ch)); boolean uCase = false; for (int i = 1; i < xml.length(); i++) { ch = xml.charAt(i); if (ch == '.') { identifier.append('_'); } else if (ch != '_' && Character.isJavaIdentifierPart(ch)) { identifier.append(Character.isUpperCase(ch) ? ch : (uCase ? Character.toUpperCase(ch) : Character.toLowerCase(ch))); uCase = false; } else uCase = true; } return identifier.toString(); }
From source file:StringUtil.java
/** * Internal method for changing the first character case. It is significantly * faster using StringBuffers then just simply Strings. */// w w w. j ava 2 s . c o m private static String changeFirstCharacterCase(boolean capitalize, String str) { int strLen = str.length(); if (strLen == 0) { return str; } StringBuilder buf = new StringBuilder(strLen); if (capitalize) { buf.append(Character.toUpperCase(str.charAt(0))); } else { buf.append(Character.toLowerCase(str.charAt(0))); } buf.append(str.substring(1)); return buf.toString(); }
From source file:com.nolanlawson.cordova.sqlite.SQLitePlugin.java
private static boolean startsWithCaseInsensitive(String str, String substr) { int i = -1;/*from w w w. ja v a 2s. c o m*/ int len = str.length(); while (++i < len) { char ch = str.charAt(i); if (!Character.isWhitespace(ch)) { break; } } int j = -1; int substrLen = substr.length(); while (++j < substrLen) { if (j + i >= len) { return false; } char ch = str.charAt(j + i); if (Character.toLowerCase(ch) != substr.charAt(j)) { return false; } } return true; }
From source file:objenome.util.bytecode.SgUtils.java
/** * Inserts an underscore before every upper case character and returns an * all lower case string. If the first character is upper case an underscore * will not be inserted.//from w w w . ja va 2 s. c om * * @param str * String to convert. * * @return Lower case + underscored text. */ public static String uppercaseToUnderscore(String str) { if (str == null) { return null; } StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (Character.isUpperCase(ch)) { if (i > 0) { sb.append('_'); } sb.append(Character.toLowerCase(ch)); } else { sb.append(ch); } } return sb.toString(); }
From source file:com.evolveum.midpoint.repo.sql.query.definition.ClassDefinitionParser.java
private String getPropertyName(String methodName) { int startIndex = 3; //method name starts with "get" if (methodName.startsWith("is")) { startIndex = 2;//ww w . ja v a 2 s . c om } char first = Character.toLowerCase(methodName.charAt(startIndex)); return Character.toString(first) + StringUtils.substring(methodName, startIndex + 1, methodName.length()); }
From source file:org.apache.usergrid.utils.Inflector.java
/** * By default, this method converts strings to UpperCamelCase. If the <code>uppercaseFirstLetter</code> argument to * false, then this method produces lowerCamelCase. This method will also use any extra delimiter characters to * identify word boundaries. <p> Examples: <p/> * <pre>// w w w. j a v a2 s . co m * inflector.camelCase("active_record",false) #=> "activeRecord" * inflector.camelCase("active_record",true) #=> "ActiveRecord" * inflector.camelCase("first_name",false) #=> "firstName" * inflector.camelCase("first_name",true) #=> "FirstName" * inflector.camelCase("name",false) #=> "name" * inflector.camelCase("name",true) #=> "Name" * </pre> * <p/> </p> * * @param lowerCaseAndUnderscoredWord the word that is to be converted to camel case * @param uppercaseFirstLetter true if the first character is to be uppercased, or false if the first character is * to be lowercased * @param delimiterChars optional characters that are used to delimit word boundaries * * @return the camel case version of the word * * @see #underscore(String, char[]) */ public String camelCase(String lowerCaseAndUnderscoredWord, boolean uppercaseFirstLetter, char... delimiterChars) { if (lowerCaseAndUnderscoredWord == null) { return null; } lowerCaseAndUnderscoredWord = lowerCaseAndUnderscoredWord.trim(); if (lowerCaseAndUnderscoredWord.length() == 0) { return ""; } if (uppercaseFirstLetter) { String result = lowerCaseAndUnderscoredWord; // Replace any extra delimiters with underscores (before the // underscores are converted in the next step)... if (delimiterChars != null) { for (char delimiterChar : delimiterChars) { result = result.replace(delimiterChar, '_'); } } // Change the case at the beginning at after each underscore ... return replaceAllWithUppercase(result, "(^|_)(.)", 2); } if (lowerCaseAndUnderscoredWord.length() < 2) { return lowerCaseAndUnderscoredWord; } return "" + Character.toLowerCase(lowerCaseAndUnderscoredWord.charAt(0)) + camelCase(lowerCaseAndUnderscoredWord, true, delimiterChars).substring(1); }