Example usage for java.lang Character toLowerCase

List of usage examples for java.lang Character toLowerCase

Introduction

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

Prototype

public static int toLowerCase(int codePoint) 

Source Link

Document

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

Usage

From source file:Main.java

public static int parseDual(String s) {
    if (s.length() < 2 || Character.toLowerCase(s.charAt(s.length() - 1)) != 'd')
        throw new NumberFormatException("not a dual number: " + s);

    if (s.length() > 33)
        throw new NumberFormatException("number has more than 32 digits:" + s);

    int val = 0;
    for (int i = 0; i < s.length() - 1; i++) {
        val = val << 1;
        switch (s.charAt(i)) {
        case '1':
            val |= 1;
            break;
        case '0':
            break;
        default:/*from w ww . jav  a  2 s . c  o m*/
            throw new NumberFormatException("not a dual number: " + s);
        }
    }
    return val;
}

From source file:Main.java

/**
 * Return a valid element name from the given string.
 *
 * <p>Letters are put to lower case and other characters are replaced by hyphens.
 * If the first character is not a letter it is replaced by 'x'.
 *
 * @param name The candidate element name
 *
 * @return A valid element name/*from   www  .  j av a2  s .  co  m*/
 */
public static String toElementName(String name) {
    if (name == null)
        return null;
    char[] elementAsChars = name.toCharArray();
    if (!Character.isLetter(elementAsChars[0])) {
        elementAsChars[0] = 'x';
    } else {
        elementAsChars[0] = Character.toLowerCase(elementAsChars[0]);
    }
    for (int i = 1; i < elementAsChars.length; i++) {
        if (!Character.isLetter(elementAsChars[i])) {
            elementAsChars[i] = '-';
        } else {
            elementAsChars[i] = Character.toLowerCase(elementAsChars[i]);
        }
    }
    return new String(elementAsChars);
}

From source file:Main.java

public static String decapitalize(String propertyName) {
    return Character.toLowerCase(propertyName.charAt(0)) + propertyName.substring(1);
}

From source file:Main.java

private static String changeFirstCharacterCase(String str, boolean capitalize) {
    if (str == null || str.length() == 0) {
        return str;
    }/*  ww  w  .  jav a  2s.c om*/
    StringBuilder sb = new StringBuilder(str.length());
    if (capitalize) {
        sb.append(Character.toUpperCase(str.charAt(0)));
    } else {
        sb.append(Character.toLowerCase(str.charAt(0)));
    }
    sb.append(str.substring(1));
    return sb.toString();
}

From source file:Utils.java

public static String uncapitalize(String str) {
    int strLen = str.length();
    if (str == null || strLen == 0) {
        return str;
    }/*w  w w  . ja va  2  s  .co m*/
    return new StringBuffer(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1))
            .toString();
}

From source file:Main.java

/**
 * Method called to figure out name of the property, given 
 * corresponding suggested name based on a method or field name.
 *
 * @param basename Name of accessor/mutator method, not including prefix
 *  ("get"/"is"/"set")/*from   w ww. j a v  a 2  s.  c  o  m*/
 */
protected static String manglePropertyName(String basename) {
    int len = basename.length();

    // First things first: empty basename is no good
    if (len == 0) {
        return null;
    }
    // otherwise, lower case initial chars
    StringBuilder sb = null;
    for (int i = 0; i < len; ++i) {
        char upper = basename.charAt(i);
        char lower = Character.toLowerCase(upper);
        if (upper == lower) {
            break;
        }
        if (sb == null) {
            sb = new StringBuilder(basename);
        }
        sb.setCharAt(i, lower);
    }
    return (sb == null) ? basename : sb.toString();
}

From source file:Main.java

public static String toXmlName(String s) {
    s = removePrefix(s);//from   w  ww . j  a  va2  s .com
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (i != 0 && Character.isUpperCase(c)) {
            sb.append("-");
        }
        sb.append(Character.toLowerCase(c));
    }
    return sb.toString();
}

From source file:Main.java

/**
 * Convert a java type into a xml name E.g. XMLType = "xmlType", String =
 * "string", StringBIG = "StringBIG"//from  w  ww  . jav  a 2s . c o m
 */
public static final String toXMLName(final String name) {
    final StringBuilder builder = new StringBuilder();
    boolean firstWord = true;
    for (int i = 0; i < name.length(); i++) {
        final char c = name.charAt(i);

        if (i == 0) {
            builder.append(Character.toLowerCase(c));
        } else {
            if (firstWord) {
                if (i + 2 < name.length() && Character.isLowerCase(name.charAt(i + 2))) {
                    firstWord = false;
                }
                builder.append(Character.toLowerCase(c));
            } else {
                builder.append(c);
            }
        }
    }

    return builder.toString();
}

From source file:Main.java

/**
 * Converts a string to title casing./*w  ww.  j  av  a 2s  .c om*/
 * @param str
 *      The string to convert.
 * @return
 *      The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }
    // skip if already contains mixed case
    if (!str.equals(str.toLowerCase()) && !str.equals(str.toUpperCase())) {
        return str;
    }

    boolean isSeparator = true;
    StringBuilder builder = new StringBuilder(str);
    final int len = builder.length();

    for (int i = 0; i < len; ++i) {
        char c = builder.charAt(i);
        if (isSeparator) {
            if (Character.isLetterOrDigit(c)) {
                // Convert to title case and switch out of whitespace mode.
                builder.setCharAt(i, Character.toTitleCase(c));
                isSeparator = false;
            }
        } else if (!Character.isLetterOrDigit(c)) {
            isSeparator = true;
        } else {
            builder.setCharAt(i, Character.toLowerCase(c));
        }
    }

    return builder.toString();
}

From source file:StringUtil.java

public static String uncaps(String string) {
    if (string.length() == 0) {
        return string;
    }/*from  w w  w.  j  a  v  a2s  .c  o m*/
    char ch = string.charAt(0);
    if (Character.isUpperCase(ch)) {
        ch = Character.toLowerCase(ch);
        return ch + string.substring(1);
    }
    return string;
}