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

/** convert given "directiveName" to "directive-name" */
private static String getDirectiveNameAsHtmlAttribute(String directiveName) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < directiveName.length(); i++) {
        char ch = directiveName.charAt(i);
        if (Character.isUpperCase(ch)) {
            sb.append('-');
            ch = Character.toLowerCase(ch);
        }//w  ww .j  a  va  2s. c om
        sb.append(ch);
    }
    return sb.toString();
}

From source file:Main.java

public static String[] splitByCamelCase(String name) {
    List<String> parts = new ArrayList<String>();
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < name.length(); i++) {
        if (i > 0 && Character.isUpperCase(name.charAt(i))) {
            parts.add(b.toString());/*from ww w  .  ja  va 2 s  .  c  om*/
            b = new StringBuilder();
        }
        b.append(Character.toLowerCase(name.charAt(i)));
    }
    parts.add(b.toString());
    return parts.toArray(new String[] {});
}

From source file:Main.java

private static int compareToGBK(String s1, String s2) {
    int ret = 0;//from   ww  w .j  av a  2s  . c o  m
    try {
        byte[] bytes1 = s1.getBytes("gbk");
        byte[] bytes2 = s2.getBytes("gbk");

        int len = Math.min(bytes1.length, bytes2.length);
        for (int i = 0; i < len; i++) {

            if (bytes1[i] > 0 && bytes2[i] > 0) {
                ret = Character.toLowerCase(bytes1[i]) - Character.toLowerCase(bytes2[i]);
                if (ret == 0)
                    ret = bytes1[i] - bytes2[i];
            } else {
                int b1 = (bytes1[i] + 256) % 256;
                int b2 = (bytes2[i] + 256) % 256;
                ret = b1 - b2;
            }

            if (ret != 0) {
                break;
            }

        }
        if (ret == 0) {
            ret = bytes1.length - bytes2.length;
        }

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return ret;
}

From source file:Main.java

private static String unEscape(String s) {
    StringBuffer sbuf = new StringBuffer();
    int l = s.length();
    int ch = -1;//from w w w . ja  va2 s. co  m
    int b, sumb = 0;
    for (int i = 0, more = -1; i < l; i++) {
        /* Get next byte b from URL segment s */
        switch (ch = s.charAt(i)) {
        case '%':
            ch = s.charAt(++i);
            int hb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            ch = s.charAt(++i);
            int lb = (Character.isDigit((char) ch) ? ch - '0' : 10 + Character.toLowerCase((char) ch) - 'a')
                    & 0xF;
            b = (hb << 4) | lb;
            break;
        case '+':
            b = ' ';
            break;
        default:
            b = ch;
        }
        /* Decode byte b as UTF-8, sumb collects incomplete chars */
        if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
            sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
            if (--more == 0)
                sbuf.append((char) sumb); // Add char to sbuf
        } else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
            sbuf.append((char) b); // Store in sbuf
        } else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
            sumb = b & 0x1f;
            more = 1; // Expect 1 more byte
        } else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
            sumb = b & 0x0f;
            more = 2; // Expect 2 more bytes
        } else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
            sumb = b & 0x07;
            more = 3; // Expect 3 more bytes
        } else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
            sumb = b & 0x03;
            more = 4; // Expect 4 more bytes
        } else /* if ((b & 0xfe) == 0xfc) */ { // 1111110x (yields 1 bit)
            sumb = b & 0x01;
            more = 5; // Expect 5 more bytes
        }
        /* We don't test if the UTF-8 encoding is well-formed */
    }
    return sbuf.toString();
}

From source file:Main.java

private static String splitCamelToHuman(final String source) {
    StringBuilder target = new StringBuilder();
    boolean isFirstChar = true;
    for (int i = 0; i < source.length(); i++) {
        Character ch = source.charAt(i);
        if (Character.isUpperCase(ch)) {
            target.append(" ");
            if (isFirstChar) {
                target.append(ch);/*from  www.j a  v a 2  s .c  om*/
                isFirstChar = false;
            } else {
                target.append(Character.toLowerCase(ch));
            }
        } else {
            target.append(ch);
        }
    }
    return target.toString();
}

From source file:Main.java

/**
 * decode Unicode string/*w  w w .j a v  a2s .  com*/
 *
 * @param s s
 * @return string
 */
public static String decodeUnicodeStr(String s) {
    StringBuilder sb = new StringBuilder(s.length());
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        char c = chars[i];
        if (c == '\\' && chars[i + 1] == 'u') {
            char cc = 0;
            for (int j = 0; j < 4; j++) {
                char ch = Character.toLowerCase(chars[i + 2 + j]);
                if ('0' <= ch && ch <= '9' || 'a' <= ch && ch <= 'f') {
                    cc |= (Character.digit(ch, 16) << (3 - j) * 4);
                } else {
                    cc = 0;
                    break;
                }
            }
            if (cc > 0) {
                i += 5;
                sb.append(cc);
                continue;
            }
        }
        sb.append(c);
    }
    return sb.toString();
}

From source file:TextUtils.java

/**
 * Tests if s starts with t, ignoring the case of the characters
 * //from  www  .  j  a v  a  2s. c o m
 * @param s
 * @param t
 * @return <code>true</code> if s.toLowerCase().equals( t.toLowerCase() ),
 *         but more efficiently
 */
public static boolean startsWithIgnoreCase(CharSequence s, CharSequence t) {
    if (s.length() < t.length()) {
        return false;
    }

    for (int i = 0; i < t.length(); i++) {
        char slc = Character.toLowerCase(s.charAt(i));
        char tlc = Character.toLowerCase(t.charAt(i));
        if (slc != tlc) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static String getter2property(String methodName) {
    if (methodName.startsWith("get") && methodName.length() > 3) {
        return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
    }//  ww  w.  j  a v  a  2  s  .com
    if (methodName.startsWith("is") && methodName.length() > 2) {
        return Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3);
    }
    return null;
}

From source file:Main.java

public static String setter2property(String methodName) {
    if (!methodName.startsWith("set") || methodName.length() < 4) {
        return null;
    }//from  w  ww . ja v a  2  s . c  o  m
    return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
}

From source file:Main.java

public static boolean containsIgnoreCase(String src, 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 = src.length() - length; i >= 0; i--) {
        // Quick check before calling the more expensive regionMatches() method:
        final char ch = src.charAt(i);
        if (ch != firstLo && ch != firstUp)
            continue;

        if (src.regionMatches(true, i, what, 0, length))
            return true;
    }/*w w w .j  a  v  a 2s . c o m*/

    return false;
}