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:org.hellojavaer.testcase.generator.TestCaseGenerator.java

private static void convertNum(long num, Character[] baseChar, Random random, StringBuilder result) {
    if (num <= 0 && result.length() == 0) {
        result.insert(0, baseChar[0]);/*from   ww  w .  j  a  v a 2 s. c o  m*/
    } else if (num > 0) {
        int i = (int) (num % baseChar.length);
        Character ch = random.nextBoolean() ? baseChar[i] : Character.toLowerCase(baseChar[i]);
        result.insert(0, ch);
        convertNum(num / baseChar.length, baseChar, random, result);
    }
}

From source file:com.netspective.commons.text.TextUtils.java

/**
 * Given a text string that defines a SQL table name or column name or other SQL identifier,
 * return a string that would be suitable for that string to be used as a caption or plain text.
 *///from  w w  w.ja v a 2  s  .  com
public String sqlIdentifierToText(String original, boolean uppercaseEachWord) {
    if (original == null || original.length() == 0)
        return original;

    StringBuffer text = new StringBuffer();
    text.append(Character.toUpperCase(original.charAt(0)));
    boolean wordBreak = false;
    for (int i = 1; i < original.length(); i++) {
        char ch = original.charAt(i);
        if (ch == '_') {
            text.append(' ');
            wordBreak = true;
        } else if (wordBreak) {
            text.append(uppercaseEachWord ? Character.toUpperCase(ch) : Character.toLowerCase(ch));
            wordBreak = false;
        } else
            text.append(Character.toLowerCase(ch));
    }
    return text.toString();
}

From source file:com.neutti.webframe.util.StringUtil.java

public static String toCamelCase(String value) {
    StringBuilder sb = new StringBuilder();

    final char delimChar = '_';
    boolean lower = false;
    for (int charInd = 0; charInd < value.length(); ++charInd) {
        final char valueChar = value.charAt(charInd);
        if (valueChar == delimChar) {
            lower = false;/*from   w w w  . ja  va  2  s  .  c o  m*/
        } else if (lower) {
            sb.append(Character.toLowerCase(valueChar));
        } else {
            sb.append(Character.toUpperCase(valueChar));
            lower = true;
        }
    }
    String str = sb.toString();
    return str.substring(0, 1).toLowerCase() + str.substring(1);
}

From source file:org.apache.hyracks.data.std.primitive.UTF8StringPointable.java

/**
 * Generates a "title" format string from an input source string, i.e., the first letter of each word
 * is in the upper case while the other letter is in the lower case.
 *
 * @param src//from  ww  w .  j  a  v a2s. c om
 *            , the input source string.
 * @param builder
 *            , a builder for the resulting string.
 * @param out
 *            , the storage for a result string.
 * @throws IOException
 */
public static void initCap(UTF8StringPointable src, UTF8StringBuilder builder, GrowableArray out)
        throws IOException {
    final int srcUtfLen = src.getUTF8Length();
    final int srcStart = src.getMetaDataLength();

    builder.reset(out, srcUtfLen);
    boolean toUpperCase = true;
    int byteIndex = 0;
    while (byteIndex < srcUtfLen) {
        char originalChar = src.charAt(srcStart + byteIndex);
        boolean isLetter = Character.isLetter(originalChar);

        // Make the first character into upper case while the later ones into lower case.
        char resultChar = toUpperCase && isLetter ? Character.toUpperCase(originalChar)
                : (isLetter ? Character.toLowerCase(originalChar) : originalChar);
        builder.appendChar(resultChar);
        byteIndex += src.charSize(srcStart + byteIndex);

        // Whether the next letter needs to switch to the upper case.
        toUpperCase = !isLetter;
    }
    builder.finish();
}

From source file:com.venkatesan.das.cardmanager.OCRCaptureActivity.java

private String toTitleCase(String str) {

    if (str == null) {
        return null;
    }/*ww  w.j  a  v a  2s  .c  om*/

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

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

    return builder.toString();
}

From source file:io.fabric8.ConnectorMojo.java

public static String camelCaseToDash(String value) {
    StringBuilder sb = new StringBuilder(value.length());
    boolean dash = false;

    for (char c : value.toCharArray()) {
        // skip dash in start
        if (sb.length() > 0 & Character.isUpperCase(c)) {
            dash = true;//from  w w  w.  j a va2s . c  o m
        }
        if (dash) {
            sb.append('-');
            sb.append(Character.toLowerCase(c));
        } else {
            // lower case first
            if (sb.length() == 0) {
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
        dash = false;
    }
    return sb.toString();
}

From source file:com.cloudera.sqoop.testutil.ManagerCompatTestCase.java

/**
 * Given a string of characters which represent hex values
 * (e.g., 'ABF00F1238'), return the string as a set of separated
 * octets, in lower case (e.g., 'ab f0 0f 12 38').
 *
 * @param str the input string of hex digits
 * @return the input string as space-separated lower-case octets. 
 *//* w  ww .  j  a va  2  s . c om*/
protected String toLowerHexString(String str) {
    // The inserted text is a hex string of the form 'ABABABAB'.
    // We return it in the form 'ab ab ab ab'.
    StringBuilder sb = new StringBuilder();
    boolean isOdd = false;
    boolean first = true;
    for (char c : str.toCharArray()) {
        if (!isOdd && !first) {
            sb.append(' ');
        }

        sb.append(Character.toLowerCase(c));
        isOdd = !isOdd;
        first = false;
    }

    return sb.toString();
}

From source file:com.nttec.everychan.ui.presentation.HtmlParser.java

private void handleStartTag(String tag, Attributes attributes) {
    if (tag.equalsIgnoreCase("br")) {
        // We don't need to handle this. TagSoup will ensure that there's a </br> for each <br>
        // so we can safely emite the linebreaks when we handle the close tag.
    } else if (tag.equalsIgnoreCase("p")) {
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
    } else if (tag.equalsIgnoreCase("div")) {
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
    } else if (tag.equalsIgnoreCase("strong")) {
        start(mSpannableStringBuilder, new Bold());
    } else if (tag.equalsIgnoreCase("b")) {
        start(mSpannableStringBuilder, new Bold());
    } else if (tag.equalsIgnoreCase("em")) {
        start(mSpannableStringBuilder, new Italic());
    } else if (tag.equalsIgnoreCase("cite")) {
        start(mSpannableStringBuilder, new Italic());
    } else if (tag.equalsIgnoreCase("dfn")) {
        start(mSpannableStringBuilder, new Italic());
    } else if (tag.equalsIgnoreCase("i")) {
        start(mSpannableStringBuilder, new Italic());
    } else if (tag.equalsIgnoreCase("s")) {
        start(mSpannableStringBuilder, new Strike());
    } else if (tag.equalsIgnoreCase("strike")) {
        start(mSpannableStringBuilder, new Strike());
    } else if (tag.equalsIgnoreCase("del")) {
        start(mSpannableStringBuilder, new Strike());
    } else if (tag.equalsIgnoreCase("big")) {
        start(mSpannableStringBuilder, new Big());
    } else if (tag.equalsIgnoreCase("small")) {
        start(mSpannableStringBuilder, new Small());
    } else if (tag.equalsIgnoreCase("font")) {
        startFont(mSpannableStringBuilder, attributes);
    } else if (tag.equalsIgnoreCase("blockquote")) {
        String classAttr = attributes.getValue("", "class");
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
        start(mSpannableStringBuilder, new Blockquote(classAttr != null && classAttr.equals("unkfunc")));
    } else if (tag.equalsIgnoreCase("tt")) {
        start(mSpannableStringBuilder, new Monospace());
    } else if (tag.equalsIgnoreCase("code")) {
        start(mSpannableStringBuilder, new Monospace());
    } else if (tag.equalsIgnoreCase("ul")) {
        mListTags.addFirst(new UlTag());
    } else if (tag.equalsIgnoreCase("ol")) {
        mListTags.addFirst(new OlTag());
    } else if (tag.equalsIgnoreCase("li")) {
        handleLi(mSpannableStringBuilder, mListTags.peek(), mListTags.size());
    } else if (tag.equalsIgnoreCase("tr")) {
        handleTr(mSpannableStringBuilder, true);
    } else if (tag.equalsIgnoreCase("td")) {
        handleTd(mSpannableStringBuilder, true);
    } else if (tag.equalsIgnoreCase("a")) {
        startA(mSpannableStringBuilder, attributes);
    } else if (tag.equalsIgnoreCase("u")) {
        start(mSpannableStringBuilder, new Underline());
    } else if (tag.equalsIgnoreCase("sup")) {
        start(mSpannableStringBuilder, new Super());
    } else if (tag.equalsIgnoreCase("sub")) {
        start(mSpannableStringBuilder, new Sub());
    } else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1'
            && tag.charAt(1) <= '6') {
        handleP(mSpannableStringBuilder, mStartLength, mLastPTagLength);
        start(mSpannableStringBuilder, new Header(tag.charAt(1) - '1'));
    } else if (tag.equalsIgnoreCase("img")) {
        startImg(mSpannableStringBuilder, attributes, mImageGetter);
    } else if (tag.equalsIgnoreCase("span")) {
        startSpan(mSpannableStringBuilder, attributes);
    } else if (tag.equalsIgnoreCase("aibquote")) {
        start(mSpannableStringBuilder, new Aibquote());
    } else if (tag.equalsIgnoreCase("aibspoiler")) {
        start(mSpannableStringBuilder, new Aibspoiler());
    } /* else if (mTagHandler != null) {
      mTagHandler.handleTag(true, tag, mSpannableStringBuilder, mReader);
      }*//*from   w  w w .  ja va 2  s. c  o m*/
}

From source file:de.homelab.madgaksha.lotsofbs.util.LocaleRootWordUtils.java

/**
 * <p>/*from w ww .  ja v a 2 s .  c  o  m*/
 * Swaps the case of a String using a word based algorithm.
 * </p>
 * 
 * <ul>
 * <li>Upper case character converts to Lower case</li>
 * <li>Title case character converts to Lower case</li>
 * <li>Lower case character after Whitespace or at start converts to Title
 * case</li>
 * <li>Other Lower case character converts to Upper case</li>
 * </ul>
 * 
 * <p>
 * Whitespace is defined by {@link Character#isWhitespace(char)}. 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>
 * 
 * @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(final String str) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }
    final char[] buffer = str.toCharArray();

    boolean whitespace = true;

    for (int i = 0; i < buffer.length; i++) {
        final char ch = buffer[i];
        if (Character.isUpperCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isTitleCase(ch)) {
            buffer[i] = Character.toLowerCase(ch);
            whitespace = false;
        } else if (Character.isLowerCase(ch)) {
            if (whitespace) {
                buffer[i] = Character.toTitleCase(ch);
                whitespace = false;
            } else {
                buffer[i] = Character.toUpperCase(ch);
            }
        } else {
            whitespace = Character.isWhitespace(ch);
        }
    }
    return new String(buffer);
}

From source file:com.github.abel533.mapperhelper.EntityHelper.java

/**
 * ?//w w  w.  ja  va  2 s  .c o m
 */
public static String underlineToCamelhump(String str) {
    Matcher matcher = Pattern.compile("_[a-z]").matcher(str);
    StringBuilder builder = new StringBuilder(str);
    for (int i = 0; matcher.find(); i++) {
        builder.replace(matcher.start() - i, matcher.end() - i, matcher.group().substring(1).toUpperCase());
    }
    if (Character.isUpperCase(builder.charAt(0))) {
        builder.replace(0, 1, String.valueOf(Character.toLowerCase(builder.charAt(0))));
    }
    return builder.toString();
}