List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:com.legstar.cob2xsd.XsdDataItem.java
/** * Turn a COBOL name to a unique XSD type name. * <p/>//from ww w. j a v a 2 s. c om * Complex type names customarily start with an uppercase character. * <p/> * The proposed name might be conflicting with another so we disambiguate * xsd type names with one of 2 options: * <ul> * <li>Appending the COBOL source line number (compatible with * legstar-schemagen)</li> * <li>Appending the parent XSD type name</li> * </ul> * * @param cobolDataItem the COBOL data item * @param elementName the element name built from the COBOL name * @param nonUniqueCobolNames a list of non unique COBOL names * @param model the translator options * @param parent used to resolve potential name conflict * @param order order within parent to disambiguate siblings * @return a nice XML type name */ public static String formatTypeName(final String elementName, final CobolDataItem cobolDataItem, final List<String> nonUniqueCobolNames, final Cob2XsdModel model, final XsdDataItem parent, final int order) { StringBuilder sb = new StringBuilder(); sb.append(Character.toUpperCase(elementName.charAt(0))); sb.append(elementName.substring(1)); if (nonUniqueCobolNames.contains(cobolDataItem.getCobolName())) { if (model.nameConflictPrependParentName()) { if (parent != null) { sb.insert(0, parent.getXsdTypeName()); } } else { sb.append(cobolDataItem.getSrceLine()); } } return sb.toString(); }
From source file:CharUtils.java
/** * Capitalize first letter in string./* w ww .j a va 2 s.co m*/ * * @param s * String to capitalize. * * @return "s" with first letter (not first character) capitalized. * Remaining characters are set to lower case. */ public static String capitalizeFirstLetter(String s) { char[] chars = s.toLowerCase().toCharArray(); for (int i = 0; i < chars.length; i++) { char ch = chars[i]; if (Character.isLetter(ch)) { chars[i] = Character.toUpperCase(ch); break; } } return new String(chars); }
From source file:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java
/** * Capitalize the first character of the name. * /* www . j a va2 s . com*/ * @param name * @return */ public static String capitalizeFirstChar(String name) { if ((name == null) || name.equals("")) { return name; } char start = name.charAt(0); if (Character.isLowerCase(start)) { start = Character.toUpperCase(start); return start + name.substring(1); } return name; }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * INTERNAL method that capitalizes the first character of a string * * @param s The string to capitalize// w ww .j a v a2 s . co m * @return The capitalized string */ private static String capitalize(String s) { if (s == null || s.length() == 0) { return ""; } char first = s.charAt(0); if (Character.isUpperCase(first)) { return s; } else { return Character.toUpperCase(first) + s.substring(1); } }
From source file:adalid.commons.util.StrUtils.java
public static String getCamelCase(String string, String gap, boolean toLowerCaseLess) { if (string == null) { return null; }//from w ww . j a va2 s .c o m String x = string.trim(); String y = ""; String z = StringUtils.isBlank(gap) ? StringUtils.EMPTY : gap.trim(); boolean b = false; boolean g = false; char c; for (int i = 0; i < x.length(); i++) { c = x.charAt(i); if (isLetterOrDigit(c)) { if (b) { y += g ? z : ""; y += Character.toUpperCase(c); } else { y += toLowerCaseLess ? c : Character.toLowerCase(c); } b = false; g = true; } else { b = true; } } return y; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.java
/** * Sets an attribute.//from w w w . j a v a 2 s . com * See also <a href="http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-F68F082"> * the DOM reference</a> * * @param name Name of the attribute to set * @param value Value to set the attribute to */ @Override public void setAttribute(String name, final String value) { getDomNodeOrDie().setAttribute(name, value); // call corresponding event handler setOnxxx if found if (!name.isEmpty()) { name = name.toLowerCase(Locale.ROOT); if (name.startsWith("on")) { try { name = Character.toUpperCase(name.charAt(0)) + name.substring(1); final Method method = getClass().getMethod("set" + name, METHOD_PARAMS_OBJECT); method.invoke(this, new Object[] { new EventHandler(getDomNodeOrDie(), name.substring(2), value) }); } catch (final NoSuchMethodException e) { //silently ignore } catch (final IllegalAccessException e) { //silently ignore } catch (final InvocationTargetException e) { throw new RuntimeException(e.getCause()); } } } }
From source file:egovframework.rte.fdl.string.EgovStringUtil.java
/** * This method convert "string_util" to/*from www . j a v a 2 s .co m*/ * "stringUtil" * @param String * targetString * @param char posChar * @return String result */ public static String convertToCamelCase(String targetString, char posChar) { StringBuffer result = new StringBuffer(); boolean nextUpper = false; String allLower = targetString.toLowerCase(); for (int i = 0; i < allLower.length(); i++) { char currentChar = allLower.charAt(i); if (currentChar == posChar) { nextUpper = true; } else { if (nextUpper) { currentChar = Character.toUpperCase(currentChar); nextUpper = false; } result.append(currentChar); } } return result.toString(); }
From source file:com.actionbarsherlock.internal.nineoldandroids.animation.PropertyValuesHolder.java
/** * Utility method to derive a setter/getter method name from a property name, where the * prefix is typically "set" or "get" and the first letter of the property name is * capitalized./*from w w w . j a va 2s . c o m*/ * * @param prefix The precursor to the method name, before the property name begins, typically * "set" or "get". * @param propertyName The name of the property that represents the bulk of the method name * after the prefix. The first letter of this word will be capitalized in the resulting * method name. * @return String the property name converted to a method name according to the conventions * specified above. */ static String getMethodName(String prefix, String propertyName) { if (propertyName == null || propertyName.length() == 0) { // shouldn't get here return prefix; } char firstLetter = Character.toUpperCase(propertyName.charAt(0)); String theRest = propertyName.substring(1); return prefix + firstLetter + theRest; }
From source file:au.org.ala.delta.util.Utils.java
/** * Capitalises the first word in the supplied text (which may contain RTF * markup) the first letter of the word is preceded by a '|'. * /*from www . j av a2s .c o m*/ * @param text * the text to capitalise. * @return the text with the first word capitalised. */ public static String capitaliseFirstWord(String text) { if (StringUtils.isEmpty(text)) { return text; } StringBuilder tmp = new StringBuilder(); tmp.append(text); int index = 0; while (index >= 0 && index < text.length() && !Character.isLetterOrDigit(tmp.charAt(index))) { if (tmp.charAt(index) == '\\') { index = RTFUtils.skipKeyword(text, index); if (index < 0 || index >= tmp.length() || Character.isLetterOrDigit(tmp.charAt(index))) { break; } } index++; } if (index >= 0 && index < text.length() && Character.isLetter(tmp.charAt(index))) { if ((index == 0) || (tmp.charAt(index - 1) != '|')) { tmp.setCharAt(index, Character.toUpperCase(tmp.charAt(index))); } else if (tmp.charAt(index - 1) == '|') { tmp.deleteCharAt(index - 1); } } return tmp.toString(); }
From source file:org.gvnix.service.roo.addon.addon.util.WsdlParserUtils.java
/** * Map an XML name to a Java identifier per the mapping rules of JSR 101 (in * version 1.0 this is "Chapter 20: Appendix: Mapping of XML Names" * /* w ww . j a v a 2 s . co m*/ * @param name is the xml name * @return the java name per JSR 101 specification */ public static String xmlNameToJava(String name) { // protect ourselves from garbage if (name == null || name.equals("")) return name; char[] nameArray = name.toCharArray(); int nameLen = name.length(); StringBuffer result = new StringBuffer(nameLen); boolean wordStart = false; // The mapping indicates to convert first character. int i = 0; while (i < nameLen && (isPunctuation(nameArray[i]) || !Character.isJavaIdentifierStart(nameArray[i]))) { i++; } if (i < nameLen) { // Decapitalization code used to be here, but we use the // Introspector function now after we filter out all bad chars. result.append(nameArray[i]); // wordStart = !Character.isLetter(nameArray[i]); wordStart = !Character.isLetter(nameArray[i]) && nameArray[i] != "_".charAt(0); } else { // The identifier cannot be mapped strictly according to // JSR 101 if (Character.isJavaIdentifierPart(nameArray[0])) { result.append("_" + nameArray[0]); } else { // The XML identifier does not contain any characters // we can map to Java. Using the length of the string // will make it somewhat unique. result.append("_" + nameArray.length); } } // The mapping indicates to skip over // all characters that are not letters or // digits. The first letter/digit // following a skipped character is // upper-cased. for (++i; i < nameLen; ++i) { char c = nameArray[i]; // if this is a bad char, skip it and remember to capitalize next // good character we encounter if (isPunctuation(c) || !Character.isJavaIdentifierPart(c)) { wordStart = true; continue; } if (wordStart && Character.isLowerCase(c)) { result.append(Character.toUpperCase(c)); } else { result.append(c); } // If c is not a character, but is a legal Java // identifier character, capitalize the next character. // For example: "22hi" becomes "22Hi" // wordStart = !Character.isLetter(c); wordStart = !Character.isLetter(c) && c != "_".charAt(0); } // covert back to a String String newName = result.toString(); // Follow JavaBean rules, but we need to check if the first // letter is uppercase first if (Character.isUpperCase(newName.charAt(0))) newName = Introspector.decapitalize(newName); // check for Java keywords if (isJavaKeyword(newName)) newName = makeNonJavaKeyword(newName); return newName; }