List of usage examples for java.lang Character toTitleCase
public static int toTitleCase(int codePoint)
From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java
/** * <p>//from ww w . java 2 s . c o m * Capitalizes a String changing the first letter to title case as per * {@link Character#toTitleCase(char)}. No other letters are changed. * </p> * <p/> * <p> * For a word based algorithm, see * {@link org.apache.commons.lang3.text.WordUtils#capitalize(String)}. A {@code null} input String * returns {@code null}. * </p> * <p/> * * <pre> * StringUtils.capitalize(null) = null * StringUtils.capitalize("") = "" * StringUtils.capitalize("cat") = "Cat" * StringUtils.capitalize("cAt") = "CAt" * </pre> * * @param str the String to capitalize, may be null * @return the capitalized String, {@code null} if null String input */ public static String capitalize(String str) { if (str == null || (str.length()) == 0) { return str; } return String.valueOf(Character.toTitleCase(str.charAt(0))) + str.substring(1); }
From source file:org.wso2.carbon.appmgt.hostobjects.HostObjectUtils.java
/** * Returns the text (key {@code text}) and color (key {@code color}) of the default thumbnail based on the specified app name. * @param appName app name/*from w ww .j a v a2 s . c o m*/ * @return default thumbnail data * @exception IllegalArgumentException if {@code appName} is {@code null} or empty */ public static Map<String, String> getDefaultThumbnail(String appName) { if (appName == null) { throw new IllegalArgumentException("Invalid argument. App name cannot be null."); } if (appName.isEmpty()) { throw new IllegalArgumentException("Invalid argument. App name cannot be empty."); } String defaultThumbnailText; if (appName.length() == 1) { // only one character in the app name defaultThumbnailText = appName; } else { // there are more than one character in the app name String[] wordsInAppName = StringUtils.split(appName); int firstCodePoint, secondCodePoint; if (wordsInAppName.length == 1) { // one word firstCodePoint = Character.toTitleCase(wordsInAppName[0].codePointAt(0)); secondCodePoint = wordsInAppName[0].codePointAt(Character.charCount(firstCodePoint)); } else { // two or more words firstCodePoint = Character.toTitleCase(wordsInAppName[0].codePointAt(0)); secondCodePoint = wordsInAppName[1].codePointAt(0); } defaultThumbnailText = (new StringBuffer()).append(Character.toChars(firstCodePoint)) .append(Character.toChars(secondCodePoint)).toString(); } String defaultThumbnailColor = DEFAULT_THUMBNAIL_COLORS[Math.abs(appName.hashCode()) % DEFAULT_THUMBNAIL_COLORS.length]; Map<String, String> defaultThumbnail = new HashMap<String, String>(2); defaultThumbnail.put("text", defaultThumbnailText); defaultThumbnail.put("color", defaultThumbnailColor); return defaultThumbnail; }
From source file:net.thucydides.maven.plugin.GenerateScenarioStepsMojo.java
private static String getClassNameFrom(String name) { int extensionIndex = name.lastIndexOf('.'); String nameWithOutExtension = name.substring(0, extensionIndex); String[] words = nameWithOutExtension.split("_"); StringBuilder builder = new StringBuilder(); for (String word : words) { builder.append(Character.toTitleCase(word.charAt(0))).append(word.substring(1)); }/* w w w . ja va2s . c om*/ return builder.toString(); }
From source file:org.transitime.gtfs.TitleFormatter.java
/** * This method copied from org.apache.commons.lang.WordUtils * but modified to also convert upper case characters to lower * characters as needed./*from w w w . j ava 2 s . com*/ * * @param str * @param delimiters Characters after which should use capital letter. * Don't need to add whitespace chars since those are already used * as delimiters in isDelimiter(). * @return */ private static String capitalize(String str, char[] delimiters) { int delimLen = (delimiters == null ? -1 : delimiters.length); if (str == null || str.length() == 0 || delimLen == 0) { return str; } int strLen = str.length(); StringBuffer buffer = new StringBuffer(strLen); boolean capitalizeNext = true; for (int i = 0; i < strLen; i++) { char ch = str.charAt(i); if (isDelimiter(ch, delimiters)) { buffer.append(ch); capitalizeNext = true; } else if (capitalizeNext) { buffer.append(Character.toTitleCase(ch)); capitalizeNext = false; } else { buffer.append(Character.toLowerCase(ch)); } } return buffer.toString(); }
From source file:org.zaproxy.zap.extension.api.GoAPIGenerator.java
private static String toTitleCase(String input) { StringBuilder titleCase = new StringBuilder(); boolean nextTitleCase = true; for (char c : input.toCharArray()) { if (Character.isSpaceChar(c)) { nextTitleCase = true;/*from www. ja v a 2s. c o m*/ } else if (nextTitleCase) { c = Character.toTitleCase(c); nextTitleCase = false; } titleCase.append(c); } return titleCase.toString(); }
From source file:com.example.touchdbtest.CouchbaseUtils.java
public static String capitalize(final String str) { final char[] buffer = str.toCharArray(); boolean capitalizeNext = true; for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false;//from w ww .j a va 2s .com } } return new String(buffer); }
From source file:fr.openwide.core.spring.util.StringUtils.java
public static String capitalize(String str, CharMatcher charMatcher) { if (str == null) { return null; }//from w ww . ja v a 2s . co m final char[] buffer = str.toCharArray(); boolean capitalizeNext = true; for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (charMatcher.matches(ch)) { capitalizeNext = true; } else if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false; } } return new String(buffer); }
From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java
/** * <p>//w w w . j av a2 s . c o m * Capitalizes all the delimiter separated words in a String. Only the first * letter of each word is changed. To convert the rest of each word to * lowercase at the same time, use {@link #capitalizeFully(String, char[])}. * </p> * * <p> * The delimiters represent a set of characters understood to separate * words. The first string character and the first non-delimiter character * after a delimiter will be capitalized. * </p> * * <p> * A <code>null</code> input String returns <code>null</code>. * Capitalization uses the Unicode title case, normally equivalent to upper * case. * </p> * * <pre> * WordUtils.capitalize(null, *) = null * WordUtils.capitalize("", *) = "" * WordUtils.capitalize(*, new char[0]) = * * WordUtils.capitalize("i am fine", null) = "I Am Fine" * WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine" * </pre> * * @param str * the String to capitalize, may be null * @param delimiters * set of characters to determine capitalization, null means * whitespace * @return capitalized String, <code>null</code> if null String input * @see #uncapitalize(String) * @see #capitalizeFully(String) * @since 2.1 */ public static String capitalize(final String str, final char... delimiters) { final int delimLen = delimiters == null ? -1 : delimiters.length; if (StringUtils.isEmpty(str) || delimLen == 0) { return str; } final char[] buffer = str.toCharArray(); boolean capitalizeNext = true; for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (isDelimiter(ch, delimiters)) { capitalizeNext = true; } else if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false; } } return new String(buffer); }
From source file:org.apache.velocity.test.BaseTestCase.java
/** * Turns a base file name into a test case name. * * @param s The base file name.//from w ww . j a va 2s . c om * @return The test case name. */ protected static final String getTestCaseName(String s) { StringBuffer name = new StringBuffer(); name.append(Character.toTitleCase(s.charAt(0))); name.append(s.substring(1, s.length()).toLowerCase()); return name.toString(); }
From source file:net.sf.jasperreports.functions.standard.TextFunctions.java
/** * Capitalizes each words of the specified text. The remaining parts of words are in lowercase. *///from ww w . ja v a 2 s . c om @Function("PROPER") @FunctionParameters({ @FunctionParameter("text") }) public static String PROPER(String text) { if (text == null) { logNullTextString(); return null; } else { String lowerCaseString = LOWER(text); StringBuilder result = new StringBuilder(); result.append(Character.toTitleCase(lowerCaseString.charAt(0))); boolean capitalizeNext = false; for (int i = 1; i < lowerCaseString.length(); i++) { char c = lowerCaseString.charAt(i); if (!isDelimiter(c)) { if (capitalizeNext) { result.append(Character.toTitleCase(c)); } else { result.append(c); } capitalizeNext = false; } else { result.append(c); capitalizeNext = true; } } return result.toString(); } }