List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.geoserver.jdbcconfig.internal.DbMappings.java
/** * @param propertyName// www . jav a 2 s.c o m * @return */ private String fixCase(String propertyName) { if (propertyName.length() > 1) { char first = propertyName.charAt(0); char second = propertyName.charAt(1); if (!Character.isUpperCase(second)) { propertyName = Character.toLowerCase(first) + propertyName.substring(1); } } return propertyName; }
From source file:org.languagetool.tagging.uk.CompoundTagger.java
private List<TaggedWord> tagEitherCase(String rightWord) { List<TaggedWord> rightWdList = wordTagger.tag(rightWord); if (rightWdList.isEmpty()) { if (Character.isUpperCase(rightWord.charAt(0))) { rightWdList = wordTagger.tag(rightWord.toLowerCase()); }//from w w w . j a v a2s.c o m } return rightWdList; }
From source file:com.netspective.commons.text.TextUtils.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. *//* w ww . j a v a2s.com*/ public String xmlTextToJavaIdentifier(String xml, boolean ucaseInitial) { if (xml == null || xml.length() == 0) return xml; String translated = (String) JAVA_RESERVED_WORD_TRANSLATION_MAP.get(xml.toString().toLowerCase()); if (translated != null) xml = translated; StringBuffer identifier = new StringBuffer(); char ch = xml.charAt(0); if (Character.isJavaIdentifierStart(ch)) identifier.append(ucaseInitial ? Character.toUpperCase(ch) : Character.toLowerCase(ch)); else { identifier.append('_'); if (Character.isJavaIdentifierPart(ch)) 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:com.evolveum.midpoint.prism.marshaller.PrismBeanInspector.java
private String getPropertyNameFromGetter(String getterName) { if ((getterName.length() > 3) && getterName.startsWith("get") && Character.isUpperCase(getterName.charAt(3))) { String propPart = getterName.substring(3); return StringUtils.uncapitalize(propPart); }/*ww w . j a v a 2 s .c o m*/ return getterName; }
From source file:com.android.tools.lint.checks.StringFormatDetector.java
/** * Checks whether the text begins with a non-unit word, pointing to a string * that should probably be a plural instead. This *///from ww w .ja v a 2s . co m private static boolean checkPotentialPlural(XmlContext context, Element element, String text, int wordBegin) { // This method should only be called if the text is known to start with a word assert Character.isLetter(text.charAt(wordBegin)); int wordEnd = wordBegin; while (wordEnd < text.length()) { if (!Character.isLetter(text.charAt(wordEnd))) { break; } wordEnd++; } // Eliminate units, since those are not sentences you need to use plurals for, e.g. // "Elevation gain: %1$d m (%2$d ft)" // We'll determine whether something is a unit by looking for // (1) Multiple uppercase characters (e.g. KB, or MiB), or better yet, uppercase characters // anywhere but as the first letter // (2) No vowels (e.g. ft) // (3) Adjacent consonants (e.g. ft); this one can eliminate some legitimate // English words as well (e.g. "the") so we should really limit this to // letter pairs that are not common in English. This is probably overkill // so not handled yet. Instead we use a simpler heuristic: // (4) Very short "words" (1-2 letters) if (wordEnd - wordBegin <= 2) { // Very short word (1-2 chars): possible unit, e.g. "m", "ft", "kb", etc return false; } boolean hasVowel = false; for (int i = wordBegin; i < wordEnd; i++) { // Uppercase character anywhere but first character: probably a unit (e.g. KB) char c = text.charAt(i); if (i > wordBegin && Character.isUpperCase(c)) { return false; } if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y') { hasVowel = true; } } if (!hasVowel) { // No vowels: likely unit return false; } String word = text.substring(wordBegin, wordEnd); // Some other known abbreviations that we don't want to count: if (word.equals("min")) { return false; } // This heuristic only works in English! if (LintUtils.isEnglishResource(context, true)) { String message = String.format("Formatting %%d followed by words (\"%1$s\"): " + "This should probably be a plural rather than a string", word); context.report(POTENTIAL_PLURAL, element, context.getLocation(element), message); // Avoid reporting multiple errors on the same string // (if it contains more than one %d) return true; } return false; }
From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java
private static String convertPropertyName(String prop) { if (Character.isUpperCase(prop.charAt(0)) && Character.isUpperCase(prop.charAt(1))) { return prop; }/*from w w w.ja va2 s . co m*/ if (Character.isDigit(prop.charAt(0))) { return prop; } return Character.toLowerCase(prop.charAt(0)) + prop.substring(1); }
From source file:eu.trentorise.opendata.josman.Josmans.java
/** * Returns the name displayed on the website as menu item for a given page. * * @param relPath path relative to the {@link JosmanProject#sourceRepoDir()} (i.e. * LICENSE.txt or docs/README.md)/*ww w . ja v a 2 s .c o m*/ */ public static String targetName(String relPath) { String htmlizedPath = htmlizePath(relPath); if (htmlizedPath.endsWith("/index.html")) { return "Usage"; } if (htmlizedPath.endsWith("/CHANGES.html")) { return "Release notes"; } String withoutFiletype = htmlizedPath.replace(".html", ""); int lastSlash = withoutFiletype.lastIndexOf("/"); String fileName = withoutFiletype; if (lastSlash != -1) { fileName = withoutFiletype.substring(lastSlash + 1); } StringBuilder sb = new StringBuilder(); sb.append(Character.toUpperCase(fileName.charAt(0))); int i = 1; while (i < fileName.length()) { char ch = fileName.charAt(i); if (i + 1 < fileName.length()) { char nextCh = fileName.charAt(i + 1); if (Character.isLowerCase(ch) && Character.isUpperCase(nextCh)) { sb.append(ch + " "); i += 1; continue; } else { if (i + 2 < fileName.length()) { char nextNextCh = fileName.charAt(i + 2); if (Character.isUpperCase(ch) && Character.isUpperCase(nextCh) && Character.isLowerCase(nextNextCh)) { sb.append(ch); sb.append(" "); sb.append(Character.toLowerCase(nextCh)); i += 2; continue; } else { if (Character.isUpperCase(ch) && Character.isUpperCase(nextCh)) { sb.append(ch); i += 1; continue; } } } } } sb.append(Character.toLowerCase(ch)); i += 1; } return sb.toString(); }
From source file:com.egt.core.util.STP.java
public static String getHumplessCase(String string, char hump) { if (string == null) { return null; }/* ww w . j a va 2s.c o m*/ String x = string.trim(); String y = ""; boolean b = false; char c; for (int i = 0; i < x.length(); i++) { c = x.charAt(i); if (Character.isUpperCase(c)) { if (b) { y += hump; } y += Character.toLowerCase(c); } else { y += c; } b = true; } return y; }
From source file:com.adaptc.mws.plugins.testing.transformations.TestMixinTransformation.java
/** * Returns the property name representation of the given name. * * @param name The name to convert/*from w ww. j a va2 s . c o m*/ * @return The property name representation */ public static String getPropertyNameRepresentation(String name) { // Strip any package from the name. int pos = name.lastIndexOf('.'); if (pos != -1) { name = name.substring(pos + 1); } // Check whether the name begins with two upper case letters. if (name.length() > 1 && Character.isUpperCase(name.charAt(0)) && Character.isUpperCase(name.charAt(1))) { return name; } String propertyName = name.substring(0, 1).toLowerCase(Locale.ENGLISH) + name.substring(1); if (propertyName.indexOf(' ') > -1) { propertyName = propertyName.replaceAll("\\s", ""); } return propertyName; }
From source file:org.dhatim.edisax.util.EDIUtils.java
public static String encodeAttributeName(String name) { String result;/* w w w .j av a 2 s. co m*/ if (name.toUpperCase().equals(name)) { result = name.toLowerCase(); } else { result = name; } result = deleteWithPascalNotation(result, '_'); result = encodeJavaIdentifier(result); if (Character.isUpperCase(result.charAt(0))) { result = Character.toLowerCase(result.charAt(0)) + result.substring(1); } if (reservedKeywords.contains(result)) { result = "_" + result; } return result; }