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

/**
 * Converts a string to title casing.//from   w ww. j  ava2 s  . c  o  m
 *
 * @param str The string to convert.
 * @return The converted string.
 */
public static String toTitleCase(String str) {
    if (str == null) {
        return null;
    }

    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:org.springframework.social.google.api.impl.ApiEnumSerializer.java

public static String enumToString(Enum<?> value) {

    if (value == null) {
        return null;
    }/*from   w  w w.  j  ava 2 s.  c o m*/

    String underscored = value.name();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < underscored.length(); i++) {
        char c = underscored.charAt(i);
        if (c == '_') {
            sb.append(Character.toUpperCase(underscored.charAt(++i)));
        } else {
            sb.append(Character.toLowerCase(c));
        }
    }
    return sb.toString();
}

From source file:Main.java

/**
 * <p>//from w w w  .  j  a  va 2 s.  c o  m
 * Swaps the case of String.
 * </p>
 * <p/>
 * <p>
 * Properly looks after making sure the start of words are Titlecase and not Uppercase.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> is returned as <code>null</code>.
 * </p>
 *
 * @param str the String to swap the case of
 * @return the modified String
 */
public static String swapCase(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);

    boolean whitespace = false;
    char ch;
    char tmp;

    for (int i = 0; i < sz; i++) {
        ch = str.charAt(i);
        if (Character.isUpperCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isTitleCase(ch)) {
            tmp = Character.toLowerCase(ch);
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                tmp = Character.toTitleCase(ch);
            } else {
                tmp = Character.toUpperCase(ch);
            }
        } else {
            tmp = ch;
        }
        buffer.append(tmp);
        whitespace = Character.isWhitespace(ch);
    }
    return buffer.toString();
}

From source file:Main.java

/**
 * <p>/*from   w  w w  . j ava2s  .  co  m*/
 * Uncapitalise all the words in a string.
 * </p>
 * <p/>
 * <p>
 * Uses {@link Character#isWhitespace(char)} as a separator between words.
 * </p>
 * <p/>
 * <p>
 * <code>null</code> will return <code>null</code>.
 * </p>
 *
 * @param str the string to uncapitalise
 * @return uncapitalised string
 */
public static String uncapitaliseAllWords(String str) {
    if (str == null) {
        return null;
    }
    int sz = str.length();
    StringBuilder buffer = new StringBuilder(sz);
    boolean space = true;
    for (int i = 0; i < sz; i++) {
        char ch = str.charAt(i);
        if (Character.isWhitespace(ch)) {
            buffer.append(ch);
            space = true;
        } else if (space) {
            buffer.append(Character.toLowerCase(ch));
            space = false;
        } else {
            buffer.append(ch);
        }
    }
    return buffer.toString();
}

From source file:com.taobao.adfs.database.tdhsocket.client.util.ConvertUtil.java

public static boolean getBooleanFromString(String v) {
    if (StringUtils.isBlank(v)) {
        return false;
    }/*ww  w . j a  v  a2s.com*/
    int c = Character.toLowerCase(v.charAt(0));
    return !(c == 'f' || c == 'n' || c == '0');
}

From source file:com.adguard.commons.lang.StringHelperUtils.java

public static boolean containsIgnoreCase(String where, String what) {
    final int length = what.length();
    if (length == 0)
        return true; // Empty string is contained

    final char firstLo = Character.toLowerCase(what.charAt(0));
    final char firstUp = Character.toUpperCase(what.charAt(0));

    for (int i = where.length() - length; i >= 0; i--) {
        // Quick check before calling the more expensive regionMatches() method:
        final char ch = where.charAt(i);
        if (ch != firstLo && ch != firstUp)
            continue;

        if (where.regionMatches(true, i, what, 0, length))
            return true;
    }//from  www  . ja v a 2 s  . co  m

    return false;
}

From source file:Main.java

/**
 * Uncapitalizes a String changing the first letter to title case as
 * per {@link Character#toLowerCase(char)}. No other letters are changed.
 *
 * For a word based algorithm, see {@link WordUtils#uncapitalize(String)}.
 * A <code>null</code> input String returns <code>null</code>.
 *
 * <pre>/*  ww w.  j ava  2s  . c om*/
 * StringUtils.uncapitalize(null)  = null
 * StringUtils.uncapitalize("")    = ""
 * StringUtils.uncapitalize("Cat") = "cat"
 * StringUtils.uncapitalize("CAT") = "cAT"
 * </pre>
 *
 * @param str  the String to uncapitalize, may be null
 * @return the uncapitalized String, <code>null</code> if null String input
 * @see WordUtils#uncapitalize(String)
 * @see #capitalize(String)
 * @since 2.0
 */
public static String uncapitalize(String str) {
    int strLen;
    if (str == null || (strLen = str.length()) == 0) {
        return str;
    }
    return new StringBuffer(strLen).append(Character.toLowerCase(str.charAt(0))).append(str.substring(1))
            .toString();
}

From source file:com.vaadin.spring.internal.Conventions.java

public static String upperCamelToLowerHyphen(String string) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < string.length(); i++) {
        char c = string.charAt(i);
        if (Character.isUpperCase(c)) {
            c = Character.toLowerCase(c);
            if (shouldPrependHyphen(string, i)) {
                sb.append('-');
            }/*from  w w  w .j a v  a2s  . c  om*/
        }
        sb.append(c);
    }
    return sb.toString();
}

From source file:com.taobao.tdhs.jdbc.util.StringUtil.java

public static int indexOfIgnoreCaseRespectMarker(int startAt, String src, String target, String marker,
        String markerCloses, boolean allowBackslashEscapes) {
    char contextMarker = Character.MIN_VALUE;
    boolean escaped = false;
    int markerTypeFound = 0;
    int srcLength = src.length();
    int ind = 0;//from   ww  w.ja va2  s .  c  o m

    for (int i = startAt; i < srcLength; i++) {
        char c = src.charAt(i);

        if (allowBackslashEscapes && c == '\\') {
            escaped = !escaped;
        } else if (contextMarker != Character.MIN_VALUE && c == markerCloses.charAt(markerTypeFound)
                && !escaped) {
            contextMarker = Character.MIN_VALUE;
        } else if ((ind = marker.indexOf(c)) != -1 && !escaped && contextMarker == Character.MIN_VALUE) {
            markerTypeFound = ind;
            contextMarker = c;
        } else if ((Character.toUpperCase(c) == Character.toUpperCase(target.charAt(0))
                || Character.toLowerCase(c) == Character.toLowerCase(target.charAt(0))) && !escaped
                && contextMarker == Character.MIN_VALUE) {
            if (startsWithIgnoreCase(src, i, target))
                return i;
        }
    }
    return -1;
}

From source file:name.martingeisse.common.util.string.StringUtil.java

/**
 * Converts an underscored name to an lower-camel-case name like
 * this: "my_foo_bar" -> "myFooBar"./*from  w  w  w  .j  a  v  a  2s  .co  m*/
 * @param s the string to convert
 * @return the lower camel case string
 */
public static String convertUnderscoresToLowerCamelCase(String s) {
    if (s.isEmpty()) {
        return s;
    }
    char firstCharacterLowerCase = Character.toLowerCase(s.charAt(0));
    return firstCharacterLowerCase
            + StringUtils.remove(WordUtils.capitalizeFully(s, UNDERSCORE_ARRAY), '_').substring(1);
}