Example usage for java.lang Character toUpperCase

List of usage examples for java.lang Character toUpperCase

Introduction

In this page you can find the example usage for java.lang Character toUpperCase.

Prototype

public static int toUpperCase(int codePoint) 

Source Link

Document

Converts the character (Unicode code point) argument to uppercase using case mapping information from the UnicodeData file.

Usage

From source file:Main.java

/**
 * converts a BCD representation of a number to a String
 * @param b - BCD representation/*from w  w w  . ja va 2s .  c  o m*/
 * @param offset - starting offset
 * @param len - BCD field len
 * @param padLeft - was padLeft packed?
 * @return the String representation of the number
 */
public static String bcd2str(byte[] b, int offset, int len, boolean padLeft) {
    StringBuilder d = new StringBuilder(len);
    int start = (((len & 1) == 1) && padLeft) ? 1 : 0;
    for (int i = start; i < len + start; i++) {
        int shift = ((i & 1) == 1 ? 0 : 4);
        char c = Character.forDigit(((b[offset + (i >> 1)] >> shift) & 0x0F), 16);
        if (c == 'd')
            c = '=';
        d.append(Character.toUpperCase(c));
    }
    return d.toString();
}

From source file:com.threecrickets.jygments.style.Style.java

public static Style getByName(String name) throws ResolutionException {
    if (Character.isLowerCase(name.charAt(0)))
        name = Character.toUpperCase(name.charAt(0)) + name.substring(1) + "Style";

    Style style = getByFullName(name);
    if (style != null)
        return style;
    else {/*  w  w w .  j a  v  a 2  s.  c o m*/
        // Try contrib package
        String pack = Jygments.class.getPackage().getName() + ".contrib";
        name = pack + "." + name;
        style = getByFullName(name);
        if (style == null)
            throw new ResolutionException("Could not load style: " + name);
        return style;
    }
}

From source file:com.xhsoft.framework.common.utils.ReflectUtil.java

/**
 * <p>Description:setFieldValue</p>
 * @param target/*w  w w.  ja v a 2 s  .c  o m*/
 * @param fname
 * @param ftype
 * @param fvalue
 * @return void
 */
@SuppressWarnings("unchecked")
public static void setFieldValue(Object target, String fname, Class ftype, Object fvalue) {
    if (target == null || fname == null || "".equals(fname)
            || (fvalue != null && !ftype.isAssignableFrom(fvalue.getClass()))) {
        return;
    }

    Class clazz = target.getClass();

    try {
        Method method = clazz
                .getDeclaredMethod("set" + Character.toUpperCase(fname.charAt(0)) + fname.substring(1), ftype);

        if (!Modifier.isPublic(method.getModifiers())) {
            method.setAccessible(true);
        }

        method.invoke(target, fvalue);

    } catch (Exception me) {
        try {
            Field field = clazz.getDeclaredField(fname);

            if (!Modifier.isPublic(field.getModifiers())) {
                field.setAccessible(true);
            }

            field.set(target, fvalue);
        } catch (Exception fe) {

            if (logger.isDebugEnabled()) {
                logger.debug(fe);
            }
        }
    }
}

From source file:StringUtil.java

public static String caps(String string) {
    if (string.length() == 0) {
        return string;
    }//from  ww w. j  a  v a  2s. c om
    char ch = string.charAt(0);
    if (Character.isLowerCase(ch)) {
        ch = Character.toUpperCase(ch);
        return ch + string.substring(1);
    }
    return string;
}

From source file:Main.java

/**
 * Capitalize the first character of the given string.
 *
 * @param string     String to capitalize.
 * @return           Capitalized string.
 *
 * @throws IllegalArgumentException    String is <kk>null</kk> or empty.
 *//* w ww  .  j  a v a 2 s .co m*/
public static String capitalize(final String string) {
    if (string == null)
        throw new NullPointerException("string");
    if (string.equals(""))
        throw new NullPointerException("string");

    return Character.toUpperCase(string.charAt(0)) + string.substring(1);
}

From source file:Main.java

/**
 * Returns a valid Java name from an XML Name.
 *
 * @param name//from w w w .java2 s .co m
 * @param isUpperCase
 * @return a valid Java name from an XML Name
 */
public static String getJavaNameFromXMLName(String name, boolean isUpperCase) {
    List<String> parsedName = parseName(name, '_');
    StringBuilder result = new StringBuilder(64 * parsedName.size());
    for (String nameComponent : parsedName) {
        if (nameComponent.length() > 0) {
            if (result.length() > 0 || isUpperCase) {
                result.append(Character.toUpperCase(nameComponent.charAt(0)));
                result.append(nameComponent.substring(1));
            } else {
                result.append(nameComponent);
            }
        }
    }

    if (result.length() == 0) {
        return "_";
    }
    if (Character.isJavaIdentifierStart(result.charAt(0))) {
        return isUpperCase ? result.toString() : decapitalizeName(result.toString());
    }
    return "_" + result;
}

From source file:Main.java

public static String capitalize(String str) {
    return (str == null || str.length() == 0) ? "" : Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

From source file:Main.java

/**
 * Generate capitalized string//from  w w w. ja v a  2s  .c o  m
 *
 * @param  line      string to be capitalized
 * @return capitalized string
 */
private static String capitalize(final String line) {
    return Character.toUpperCase(line.charAt(0)) + line.substring(1);
}

From source file:com.google.flightmap.parsing.util.StringUtils.java

/**
 * Returns mixed-case version of {@code text}.
 * <p>// w  ww. j  a  v  a  2 s  .  c  o  m
 * The first letter of each word is capitalized, the rest are lower case.
 * Words are delimited by spaces and special characters (except single-quote).
 * "REID-HILLVIEW" becomes "Reid-Hillview".
 * 
 * @return mixed-case version of {@code text} with each word capitalized.
 */
public static String capitalize(final String text) {
    final StringBuilder sb = new StringBuilder(WordUtils.capitalize(text.toLowerCase()));
    boolean makeNextLetterUpper = false;
    for (int i = 0; i < sb.length(); ++i) {
        final char cur = sb.charAt(i);
        if (Character.isWhitespace(cur)) {
            continue; // Skip whitespace
        } else if (Character.isLetterOrDigit(cur)) {
            if (makeNextLetterUpper) {
                sb.setCharAt(i, Character.toUpperCase(cur));
                makeNextLetterUpper = false;
            } else {
                continue; // Skip character if no change is neded
            }
        } else { // Not whitespace, letter or digit:  we assume punctuation.
            makeNextLetterUpper = cur != '\''; // Ignore single quote (John'S, Susie'S, ...)
        }
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Finds the index of the first word that starts with the given prefix.
 * <p>/*from  w w  w .  j  av a2  s .c  om*/
 * If not found, returns -1.
 *
 * @param text the text in which to search for the prefix
 * @param prefix the text to find, in upper case letters
 */
public static int indexOfWordPrefix(CharSequence text, String prefix) {
    if (prefix == null || text == null) {
        return -1;
    }

    int textLength = text.length();
    int prefixLength = prefix.length();

    if (prefixLength == 0 || textLength < prefixLength) {
        return -1;
    }

    int i = 0;
    while (i < textLength) {
        // Skip non-word characters
        while (i < textLength && !Character.isLetterOrDigit(text.charAt(i))) {
            i++;
        }

        if (i + prefixLength > textLength) {
            return -1;
        }

        // Compare the prefixes
        int j;
        for (j = 0; j < prefixLength; j++) {
            if (Character.toUpperCase(text.charAt(i + j)) != prefix.charAt(j)) {
                break;
            }
        }
        if (j == prefixLength) {
            return i;
        }

        // Skip this word
        while (i < textLength && Character.isLetterOrDigit(text.charAt(i))) {
            i++;
        }
    }

    return -1;
}