List of usage examples for java.lang Character toUpperCase
public static int toUpperCase(int codePoint)
From source file:Main.java
/** * <p>Swaps the case of a String changing upper and title case to * lower case, and lower case to upper case.</p> * * <ul>//ww w .j a v a 2 s .c om * <li>Upper case character converts to Lower case</li> * <li>Title case character converts to Lower case</li> * <li>Lower case character converts to Upper case</li> * </ul> * * <p>For a word based algorithm, see {@link WordUtils#swapCase(String)}. * A <code>null</code> input String returns <code>null</code>.</p> * * <pre> * StringUtils.swapCase(null) = null * StringUtils.swapCase("") = "" * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone" * </pre> * * <p>NOTE: This method changed in Lang version 2.0. * It no longer performs a word based algorithm. * If you only use ASCII, you will notice no change. * That functionality is available in WordUtils.</p> * * @param str the String to swap case, may be null * @return the changed String, <code>null</code> if null String input */ public static String swapCase(String str) { int strLen; if (str == null || (strLen = str.length()) == 0) { return str; } StringBuffer buffer = new StringBuffer(strLen); char ch = 0; for (int i = 0; i < strLen; i++) { ch = str.charAt(i); if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isTitleCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { ch = Character.toUpperCase(ch); } buffer.append(ch); } return buffer.toString(); }
From source file:importer.handler.post.stages.StageThreeText.java
/** * Create an instance and add files later * @param filter the name of the text filter to apply * @param dict the name of the dictionary to use for hyphenation * @param hhExceptions the hard hyphen exceptions list */// w w w . j a v a2 s . c om public StageThreeText(String filterName, String dict, String hhExceptions) throws ImporterException { super(); try { if (filterName.length() > 0) { char first = filterName.charAt(0); first = Character.toUpperCase(first); filterName = first + filterName.substring(1); Class c = Class.forName("importer.filters." + filterName + "Filter"); filter = (Filter) c.newInstance(); if (filter != null) { filter.setDict(dict); filter.setHHExceptions(hhExceptions); } } else throw new ImporterException("filter name emtpy"); } catch (Exception e) { } }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.spelling.SurfaceFormSpellChecker.java
public static String getCorrection(String text) { // All uppercase normalization HONG KONG => Hong Kong String noPunc = text.replaceAll("[^A-Z0-9]*", ""); if (StringUtils.isAllUpperCase(noPunc) && noPunc.length() > 3) { char[] letters = text.toLowerCase().toCharArray(); for (int i = 0; i < letters.length; i++) { if (i == 0 || !Character.isLetter(letters[i - 1]) && Character.isLetter(letters[i])) { letters[i] = Character.toUpperCase(letters[i]); }// ww w . j a v a 2 s.c o m } return new String(letters); } // Spell check if (correctionCache.get(text) != null) { return String.valueOf(correctionCache.get(text)); } else { if (caching) { String correction = getGoogleCorrection(text); correctionCache.put(text, correction); return correction; } } return text; }
From source file:Main.java
/** * Green implementation of regionMatches. * * @param cs the {@code CharSequence} to be processed * @param ignoreCase whether or not to be case insensitive * @param thisStart the index to start on the {@code cs} CharSequence * @param substring the {@code CharSequence} to be looked for * @param start the index to start on the {@code substring} CharSequence * @param length character length of the region * @return whether the region matched/*from w w w .j a va2 s. c o m*/ */ static boolean regionMatches(final CharSequence cs, final boolean ignoreCase, final int thisStart, final CharSequence substring, final int start, final int length) { if (cs instanceof String && substring instanceof String) { return ((String) cs).regionMatches(ignoreCase, thisStart, (String) substring, start, length); } int index1 = thisStart; int index2 = start; int tmpLen = length; // Extract these first so we detect NPEs the same as the java.lang.String version final int srcLen = cs.length() - thisStart; final int otherLen = substring.length() - start; // Check for invalid parameters if (thisStart < 0 || start < 0 || length < 0) { return false; } // Check that the regions are long enough if (srcLen < length || otherLen < length) { return false; } while (tmpLen-- > 0) { final char c1 = cs.charAt(index1++); final char c2 = substring.charAt(index2++); if (c1 == c2) { continue; } if (!ignoreCase) { return false; } // The same check as in String.regionMatches(): if (Character.toUpperCase(c1) != Character.toUpperCase(c2) && Character.toLowerCase(c1) != Character.toLowerCase(c2)) { return false; } } return true; }
From source file:StringUtils.java
private static String changeFirstCharacterCase(String str, boolean capitalize) { if (str == null || str.length() == 0) { return str; }//from www . j a v a2 s . co m StringBuffer buf = new StringBuffer(str.length()); 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.rstar.glass.speechtotextreceiver.watson.Result.java
public String parse(JSONObject json) { String result = finalizedData; try {/*from w w w.java 2 s . c om*/ if (json.has("results")) { //if has result Savelog.d(TAG, debug, "Results message: "); JSONArray results = json.getJSONArray("results"); for (int i = 0; i < results.length(); i++) { JSONObject obj = results.getJSONObject(i); JSONArray alternatives = obj.getJSONArray("alternatives"); String transcript = alternatives.getJSONObject(0).getString("transcript"); String intermediate = Character.toUpperCase(transcript.charAt(0)) + transcript.substring(1); if (obj.getString("final").equals("true")) { String fullstop = ". "; finalizedData += intermediate.substring(0, intermediate.length() - 1) + fullstop; result = finalizedData; } else { result = finalizedData + intermediate; } break; } } } catch (Exception e) { Savelog.w(TAG, "Unrecognized json object"); result = "(unrecognized)"; } return result; }
From source file:org.springframework.social.google.api.impl.ApiEnumDeserializer.java
@Override public T deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String camelCase = jp.getText(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < camelCase.length(); i++) { char c = camelCase.charAt(i); if (Character.isUpperCase(c)) { sb.append('_').append(c); } else {//from ww w .jav a 2 s. c om sb.append(Character.toUpperCase(c)); } } @SuppressWarnings({ "rawtypes", "unchecked" }) T value = (T) Enum.valueOf((Class) type, sb.toString()); return value; }
From source file:com.rstar.mobile.speechtotextbroadcaster.watson.Result.java
public String parse(JSONObject json) { String result = finalizedData; try {/* ww w.ja v a 2 s .c om*/ if (json.has("results")) { //if has result Savelog.d(TAG, debug, "Results message: "); JSONArray results = json.getJSONArray("results"); for (int i = 0; i < results.length(); i++) { JSONObject obj = results.getJSONObject(i); JSONArray alternatives = obj.getJSONArray("alternatives"); String transcript = alternatives.getJSONObject(0).getString("transcript"); String intermediate = Character.toUpperCase(transcript.charAt(0)) + transcript.substring(1); if (obj.getString("final").equals("true")) { String fullstop = ". "; // Once the total length of text is beyond limit, reset if (finalizedData.length() + intermediate.length() > MaxLength) { finalizedData = intermediate.substring(0, intermediate.length() - 1) + fullstop; } else { // no need to reset. Just add data finalizedData += intermediate.substring(0, intermediate.length() - 1) + fullstop; } result = finalizedData; } else { result = finalizedData + intermediate; } break; } } } catch (Exception e) { Savelog.w(TAG, "Unrecognized json object"); result = "(unrecognized)"; } return result; }
From source file:com.adaptris.core.marshaller.xstream.XStreamUtils.java
/** * Converts a lowercase hyphen separated format into a camelcase based * format. Used by the unmarshalling process to convert an xml element into * a java class/field name./*w w w . j a v a 2 s . co m*/ * * @param xmlElementName * - Current element name to be processed. * @return translated name */ public static String toFieldName(String xmlElementName) { if (xmlElementName == null) { return null; } if (xmlElementName.length() == 0) { return xmlElementName; } if (xmlElementName.length() == 1) { return xmlElementName.toLowerCase(); } // -- Follow the Java beans Introspector::decapitalize // -- convention by leaving alone String that start with // -- 2 uppercase characters. if (Character.isUpperCase(xmlElementName.charAt(0)) && Character.isUpperCase(xmlElementName.charAt(1))) { return xmlElementName; } // -- process each character StringBuilder input = new StringBuilder(xmlElementName); StringBuilder output = new StringBuilder(); output.append(Character.toLowerCase(input.charAt(0))); boolean multiHyphens = false; for (int i = 1; i < input.length(); i++) { char ch = input.charAt(i); if (ch == '-') { if (input.charAt(++i) != '-') { output.append(Character.toUpperCase(input.charAt(i))); } else { multiHyphens = true; } } else { if (multiHyphens) { output.append(Character.toUpperCase(ch)); } else { output.append(ch); } multiHyphens = false; } } return output.toString(); }
From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java
/** * Decodes a field name from XML notation (e.g. my-field-name) to a valid Java field name (e.g. myFieldName) *///from ww w.j a va 2 s .c o m private static final String decodeFieldName(final String pXmlFieldName) { // StringBuilder for constructing the resulting field name StringBuilder str = new StringBuilder(); // Number of characters in the XML-encoded field name int fieldNameLength = pXmlFieldName.length(); char currentChar; for (int i = 0; i < fieldNameLength; i++) { currentChar = pXmlFieldName.charAt(i); if (currentChar == '-') { str.append(Character.toUpperCase(pXmlFieldName.charAt(++i))); } else { str.append(currentChar); } } return str.toString(); }