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:br.msf.commons.util.CharSequenceUtils.java

public static boolean isLowerCase(final CharSequence sequence) {
    if (isEmpty(sequence)) {
        return true;
    }/*from   w  ww  .  ja v  a2s.com*/
    for (int i = 0; i < sequence.length(); i++) {
        char c = sequence.charAt(i);
        if (c != Character.toLowerCase(c)) {
            return false;
        }
    }
    return true;
}

From source file:StringUtil.java

/**
 * Finds the first occurrence of a character in the given source but within limited range (start, end].
 *//*from w  ww  . j av a2  s.  c o  m*/
public static int indexOfIgnoreCase(String src, char c, int startIndex, int endIndex) {
    if (startIndex < 0) {
        startIndex = 0;
    }
    int srclen = src.length();
    if (endIndex > srclen) {
        endIndex = srclen;
    }
    c = Character.toLowerCase(c);
    for (int i = startIndex; i < endIndex; i++) {
        if (Character.toLowerCase(src.charAt(i)) == c) {
            return i;
        }
    }
    return -1;
}

From source file:edu.cornell.mannlib.vedit.util.Stemmer.java

public static String StemString(String inputStr, int maxLength) {
    String outputStr = "";

    int previousCh = 0;
    char[] w = new char[maxLength];
    char[] inputArray = inputStr.toCharArray();
    Stemmer s = new Stemmer();
    int inputArrayIndex = 0, stemmerInputBufferIndex = 0, ch = 0;
    for (inputArrayIndex = 0; inputArrayIndex < inputArray.length; inputArrayIndex++) {
        ch = inputArray[inputArrayIndex];
        if (Character.isLetter((char) ch)) {
            stemmerInputBufferIndex = 0; // start collecting letters for a new word
            while (inputArrayIndex < inputArray.length) { // keep reading until hit character other than a letter
                ch = Character.toLowerCase((char) ch);
                w[stemmerInputBufferIndex] = (char) ch;
                if (stemmerInputBufferIndex < maxLength - 1) {
                    stemmerInputBufferIndex++;
                }// ww w. j  a v a  2  s .  c  o m
                if (inputArrayIndex < inputArray.length - 1) {
                    previousCh = ch;
                    ch = inputArray[++inputArrayIndex];
                    if (!Character.isLetter((char) ch)) { // parse the word in preparation for starting a new one
                        for (int c = 0; c < stemmerInputBufferIndex; c++) { // copy to stemmer internal buffer
                            s.add(w[c]);
                        }
                        s.stem();
                        {
                            String u;
                            u = s.toString();
                            outputStr += u;
                            if (ch == '-') { // replace - with space
                                outputStr += " ";
                            } else if (ch == '.') {
                                if (Character.isDigit((char) previousCh)) {
                                    outputStr += ".";
                                } else {
                                    outputStr += " ";
                                    //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
                                }
                            } else {
                                Character Ch = new Character((char) ch);
                                outputStr += Ch.toString();
                            }
                            stemmerInputBufferIndex = 0; // to avoid repeats after )
                        }
                        break;
                    }
                } else {
                    break;
                }
            }
        } else if (Character.isWhitespace((char) ch)) {
            if (!Character.isWhitespace((char) previousCh)) {
                if (previousCh != '.') {
                    Character Ch = new Character((char) ch);
                    outputStr += Ch.toString();
                }
            }
        } else if (ch == '(') { // open paren; copy all characters until close paren
            while (ch != ')') {
                if (inputArrayIndex < inputArray.length) {
                    ch = inputArray[inputArrayIndex++];
                } else {
                    log.trace("");
                    log.trace("1 short of EOS in paren at pos: " + inputArrayIndex + " of " + inputStr);
                    break;
                }
                Character Ch = new Character((char) ch);
                //outputStr += Ch.toString();
                //System.out.print( Ch.toString() );
            }
            //log.trace("");
            /* not needed -- just duplicates close paren
            if ( ch == ')') {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace( Ch.toString() );
            }
            */
            stemmerInputBufferIndex = 0;
        } else if (ch == ')') { // when is last character of input string
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
            log.trace(Ch.toString());
            log.trace("found close paren at position: " + inputArrayIndex + " of input term " + inputStr);
        } else if (ch == '-') { // replace - with space
            outputStr += " ";
        } else if (ch == '.') {
            if (Character.isDigit((char) previousCh)) {
                outputStr += ".";
            } else {
                outputStr += " ";
                //previousCh = 32; // set to whitespace; extra spaces should be filtered out on next pass
            }
        } else {
            Character Ch = new Character((char) ch);
            outputStr += Ch.toString();
        }
        previousCh = ch;
        if (ch < 0)
            break;
    }

    if (stemmerInputBufferIndex > 0) {
        for (int c = 0; c < stemmerInputBufferIndex; c++) {
            s.add(w[c]);
        }
        s.stem();

        String u;
        u = s.toString();
        outputStr += u;
    }

    return outputStr == null ? (outputStr.equals("") ? null : outputStr.trim()) : outputStr.trim();
}

From source file:org.ballerinalang.langserver.compiler.format.TextDocumentFormatUtil.java

/**
 * Convert given name to the Json object name.
 *
 * @param name      Name to be converted
 * @param prefixLen Length of prefix/*from  ww w . j a va2s  . c o m*/
 * @return {@link String}   Converted value
 */
public static String toJsonName(String name, int prefixLen) {
    return Character.toLowerCase(name.charAt(prefixLen)) + name.substring(prefixLen + 1);
}

From source file:com.roche.sequencing.bioinformatics.common.utils.FileUtil.java

public static boolean fileContainsText(IInputStreamFactory inputStreamFactory, String text, boolean ignoreCase)
        throws IOException {
    boolean match = false;
    int indexInText = 0;

    InputStream inputStream;/*from w w  w . ja  va2 s  .  co  m*/
    if (GZipUtil.isCompressed(inputStreamFactory)) {
        inputStream = new GZIPInputStream(inputStreamFactory.createInputStream());
    } else {
        inputStream = new BufferedInputStream(inputStreamFactory.createInputStream());
    }
    try {
        byte[] character = new byte[1024];
        int readChars = 0;
        loop: while ((readChars = inputStream.read(character)) != -1) {
            for (int i = 0; i < readChars; ++i) {
                char currentChar = (char) character[i];
                char charToCompare = text.charAt(indexInText);

                if (ignoreCase) {
                    currentChar = Character.toLowerCase(currentChar);
                    charToCompare = Character.toLowerCase(charToCompare);
                }

                if ((currentChar) == charToCompare) {
                    indexInText++;
                } else {
                    indexInText = 0;
                    charToCompare = text.charAt(indexInText);
                    if (ignoreCase) {
                        charToCompare = Character.toLowerCase(charToCompare);
                    }
                    if (currentChar == text.charAt(indexInText)) {
                        indexInText++;
                    }
                }
                if (indexInText >= text.length()) {
                    match = true;
                    break loop;
                }
            }
        }
    } finally {
        inputStream.close();
    }
    return match;
}

From source file:com.gargoylesoftware.htmlunit.javascript.SimpleScriptable.java

@Override
protected boolean isReadOnlySettable(final String name, final Object value) {
    for (final Method m : getClass().getMethods()) {
        final JsxGetter jsxGetter = m.getAnnotation(JsxGetter.class);
        if (jsxGetter != null) {
            String methodProperty;
            if (jsxGetter.propertyName().isEmpty()) {
                final int prefix = m.getName().startsWith("is") ? 2 : 3;
                methodProperty = m.getName().substring(prefix);
                methodProperty = Character.toLowerCase(methodProperty.charAt(0)) + methodProperty.substring(1);
            } else {
                methodProperty = jsxGetter.propertyName();
            }//from ww w. java  2  s  . co  m
            if (methodProperty.equals(name)) {
                final CanSetReadOnly canSetReadOnly = m.getAnnotation(CanSetReadOnly.class);
                if (canSetReadOnly != null) {
                    switch (canSetReadOnly.value()) {
                    case YES:
                        return true;
                    case IGNORE:
                        return false;
                    case EXCEPTION:
                        throw ScriptRuntime.typeError3("msg.set.prop.no.setter", name, getClassName(),
                                Context.toString(value));
                    default:
                    }
                }
            }
        }
    }
    return true;
}

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

/**
 * Generates a lower case string of an input string.
 *
 * @param src//  w ww .  ja  va  2s .  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 lowercase(UTF8StringPointable src, UTF8StringBuilder builder, GrowableArray out)
        throws IOException {
    final int srcUtfLen = src.getUTF8Length();
    final int srcStart = src.getMetaDataLength();

    builder.reset(out, srcUtfLen);
    int byteIndex = 0;
    while (byteIndex < srcUtfLen) {
        builder.appendChar(Character.toLowerCase(src.charAt(srcStart + byteIndex)));
        byteIndex += src.charSize(srcStart + byteIndex);
    }
    builder.finish();
}

From source file:org.aksw.simba.cetus.yago.YagoBasedTypeSearcher.java

private boolean isMatchingDirectly(Resource matchingType, String label) {
    String typeName = matchingType.getLocalName();
    if (typeName.startsWith("wordnet_")) {
        typeName = typeName.substring(8);
    }//from ww w .  j ava  2  s .com
    StringBuilder builder = new StringBuilder();
    char chars[] = typeName.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (chars[i] == '_') {
            builder.append(' ');
        } else if (!Character.isDigit(chars[i])) {
            builder.append(Character.toLowerCase(chars[i]));
        }
    }
    typeName = builder.toString().trim();
    return typeName.equals(label);
}

From source file:org.apache.ddlutils.task.DumpMetadataTask.java

/**
 * Derives the property name from the given method name.
 * /*from w  w  w  .ja  va 2 s  .co m*/
 * @param methodName The method name
 * @return The property name
 */
private String getPropertyName(String methodName) {
    if (methodName.startsWith("get")) {
        if (Character.isLowerCase(methodName.charAt(4))) {
            return Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
        } else {
            return methodName.substring(3);
        }
    } else if (methodName.startsWith("is")) {
        if (Character.isLowerCase(methodName.charAt(3))) {
            return Character.toLowerCase(methodName.charAt(2)) + methodName.substring(3);
        } else {
            return methodName.substring(2);
        }
    } else {
        return methodName;
    }
}

From source file:ips1ap101.lib.base.util.StrUtils.java

public static String getCamelCase(String string, String gap, boolean toLowerCaseLess) {
    if (string == null) {
        return null;
    }/*from w w w. j a  v  a 2s.  c o  m*/
    String x = string.trim();
    String y = "";
    String z = StringUtils.isBlank(gap) ? StringUtils.EMPTY : gap.trim();
    boolean b = false;
    boolean g = false;
    char c;
    for (int i = 0; i < x.length(); i++) {
        c = x.charAt(i);
        switch (c) {
        case '_':
        case '-':
        case '.':
            b = true;
            break;
        default:
            if (b) {
                y += g ? z : "";
                y += Character.toUpperCase(c);
            } else {
                y += toLowerCaseLess ? c : Character.toLowerCase(c);
            }
            b = false;
            g = true;
            break;
        }
    }
    return y;
}