List of usage examples for java.lang Character isUpperCase
public static boolean isUpperCase(int codePoint)
From source file:org.botlibre.util.Utils.java
/** * Check if the text is all upper case./*from w w w .j a va 2 s . c om*/ */ public static boolean isCaps(String text) { boolean hasCaps = false; for (int index = 0; index < text.length(); index++) { char character = text.charAt(index); if (Character.isLetter(character)) { if (!Character.isUpperCase(character)) { return false; } hasCaps = true; } } return hasCaps; }
From source file:org.apache.openjpa.lib.conf.ConfigurationImpl.java
/** * Convert <code>propName</code> to a lowercase-with-hyphens-style string. * This algorithm is only designed for mixes of uppercase and lowercase * letters and lone digits. A more sophisticated conversion should probably * be handled by a proper parser generator or regular expressions. *//*from ww w. ja v a2 s . c om*/ public static String toXMLName(String propName) { if (propName == null) return null; StringBuilder buf = new StringBuilder(); char c; for (int i = 0; i < propName.length(); i++) { c = propName.charAt(i); // convert sequences of all-caps to downcase with dashes around // them. put a trailing cap that is followed by downcase into the // downcase word. if (i != 0 && Character.isUpperCase(c) && (Character.isLowerCase(propName.charAt(i - 1)) || (i > 1 && i < propName.length() - 1 && Character.isUpperCase(propName.charAt(i - 1)) && Character.isLowerCase(propName.charAt(i + 1))))) buf.append('-'); // surround sequences of digits with dashes. if (i != 0 && ((!Character.isLetter(c) && Character.isLetter(propName.charAt(i - 1))) || (Character.isLetter(c) && !Character.isLetter(propName.charAt(i - 1))))) buf.append('-'); buf.append(Character.toLowerCase(c)); } return buf.toString(); }
From source file:org.python.pydev.core.docutils.StringUtils.java
public static String asStyleLowercaseUnderscores(String string) { int len = string.length(); FastStringBuffer buf = new FastStringBuffer(len * 2); int lastState = 0; for (int i = 0; i < len; i++) { char c = string.charAt(i); if (Character.isUpperCase(c)) { if (lastState != STATE_UPPER) { if (buf.length() > 0 && buf.lastChar() != '_') { buf.append('_'); }/*w ww. j a va 2 s .com*/ } buf.append(Character.toLowerCase(c)); lastState = STATE_UPPER; } else if (Character.isDigit(c)) { if (lastState != STATE_NUMBER) { if (buf.length() > 0 && buf.lastChar() != '_') { buf.append('_'); } } buf.append(c); lastState = STATE_NUMBER; } else { buf.append(c); lastState = STATE_LOWER; } } return buf.toString(); }
From source file:CharUtils.java
/** * Get case value for a string.//ww w .j av a 2s . c o m * * @param s * The string. * * @return Case value. 0 = all letters are lower case 1 = first letter * (only) is upper case 2 = first letter is not upper case, but some * letters after first are upper case 3 = all letters are upper case */ public static int getLetterCase(String s) { int result = 0; int capLetCount = 0; int letCount = 0; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (Character.isLetter(ch)) { letCount++; if (Character.isUpperCase(ch)) { if (letCount == 1) result = 1; capLetCount++; } } } if (letCount == capLetCount) { result = 3; } else if ((result == 0) && (capLetCount > 0)) { result = 2; } return result; }
From source file:org.languagetool.rules.de.CaseRule.java
private void potentiallyAddUppercaseMatch(List<RuleMatch> ruleMatches, AnalyzedTokenReadings[] tokens, int i, AnalyzedTokenReadings analyzedToken, String token, AnalyzedTokenReadings lowercaseReadings, AnalyzedSentence sentence) {//from w ww . j av a2s . com boolean isUpperFirst = Character.isUpperCase(token.charAt(0)); if (isUpperFirst && token.length() > 1 && // length limit = ignore abbreviations !tokens[i].isIgnoredBySpeller() && !tokens[i].isImmunized() && !sentenceStartExceptions.contains(tokens[i - 1].getToken()) && !exceptions.contains(token) && !StringTools.isAllUppercase(token) && !isLanguage(i, tokens, token) && !isProbablyCity(i, tokens, token) && !GermanHelper.hasReadingOfType(analyzedToken, POSType.PROPER_NOUN) && !analyzedToken.isSentenceEnd() && !isEllipsis(i, tokens) && !isNumbering(i, tokens) && !isNominalization(i, tokens, token, lowercaseReadings) && !isAdverbAndNominalization(i, tokens) && !isSpecialCase(i, tokens) && !isAdjectiveAsNoun(i, tokens, lowercaseReadings) && !isExceptionPhrase(i, tokens)) { String fixedWord = StringTools.lowercaseFirstChar(tokens[i].getToken()); if (":".equals(tokens[i - 1].getToken())) { AnalyzedTokenReadings[] subarray = new AnalyzedTokenReadings[i]; System.arraycopy(tokens, 0, subarray, 0, i); if (isVerbFollowing(i, tokens, lowercaseReadings) || getTokensWithPartialPosTagCount(subarray, "VER") == 0) { // no error } else { addRuleMatch(ruleMatches, sentence, COLON_MESSAGE, tokens[i], fixedWord); } return; } addRuleMatch(ruleMatches, sentence, UPPERCASE_MESSAGE, tokens[i], fixedWord); } }
From source file:adalid.commons.util.StrUtils.java
public static String getHumplessCase(String string, String hump) { if (string == null) { return null; }// w w w . java2s .c om if (hump == null) { return null; } if (isNotMixedCase(string)) { return string; } 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 = isLetterOrDigit(c); } return y; }
From source file:egovframework.rte.fdl.string.EgovStringUtil.java
/** * Convert a camel case string to underscore * representation.//from www.j a v a 2 s .c o m * @param camelCase * Camel case name. * @return Underscore representation of the camel * case string. */ public static String convertToUnderScore(String camelCase) { String result = ""; for (int i = 0; i < camelCase.length(); i++) { char currentChar = camelCase.charAt(i); // This is starting at 1 so the result does // not end up with an // underscore at the begin of the value if (i > 0 && Character.isUpperCase(currentChar)) { result = result.concat("_"); } result = result.concat(Character.toString(currentChar).toLowerCase()); } return result; }
From source file:org.python.pydev.core.docutils.StringUtils.java
public static boolean isAllUpper(String string) { int len = string.length(); for (int i = 0; i < len; i++) { char c = string.charAt(i); if (Character.isLetter(c) && !Character.isUpperCase(c)) { return false; }//w w w. jav a 2s. com } return true; }
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" * /*from w ww . j a va 2s. c om*/ * @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; }
From source file:org.openx.data.jsonserde.json.JSONObject.java
private void populateMap(Object bean) { Class klass = bean.getClass(); // If klass is a System class then set includeSuperClass to false. boolean includeSuperClass = klass.getClassLoader() != null; Method[] methods = (includeSuperClass) ? klass.getMethods() : klass.getDeclaredMethods(); for (int i = 0; i < methods.length; i += 1) { try {//from w w w . java 2 s . c o m Method method = methods[i]; if (Modifier.isPublic(method.getModifiers())) { String name = method.getName(); String key = ""; if (name.startsWith("get")) { if (name.equals("getClass") || name.equals("getDeclaringClass")) { key = ""; } else { key = name.substring(3); } } else if (name.startsWith("is")) { key = name.substring(2); } if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) { if (key.length() == 1) { key = key.toLowerCase(); } else if (!Character.isUpperCase(key.charAt(1))) { key = key.substring(0, 1).toLowerCase() + key.substring(1); } Object result = method.invoke(bean, (Object[]) null); if (result != null) { map.put(key, wrap(result)); } } } } catch (Exception ignore) { } } }