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:nodomain.freeyourgadget.gadgetbridge.util.LanguageUtils.java

/**
 * Replaces unsupported symbol to english by {@code transliterateMap}
 * @param c input char/*  w  ww.  j  a  v a  2s . c om*/
 * @return replacement text
 */
private static String transliterate(char c) {
    char lowerChar = Character.toLowerCase(c);

    if (transliterateMap.containsKey(lowerChar)) {
        String replace = transliterateMap.get(lowerChar);

        if (lowerChar != c) {
            return WordUtils.capitalize(replace);
        }

        return replace;
    }

    return String.valueOf(c);
}

From source file:org.hako.dao.mapper.AnnotationMapper.java

/**
 * Convert property name to dash separated column name.
 * {@code dateCreated => date_created}.
 * //from w  w  w .jav  a  2 s.c om
 * @param propertyName property name
 * @return dash separated name
 */
String toDashSeparated(String propertyName) {
    StringBuilder builder = new StringBuilder();
    for (char c : propertyName.toCharArray()) {
        if (Character.isUpperCase(c)) {
            builder.append('_').append(Character.toLowerCase(c));
        } else {
            builder.append(c);
        }
    }
    return builder.toString();
}

From source file:org.hippoecm.frontend.plugins.yui.javascript.Setting.java

private String toConfigKey(String camelKey) {
    StringBuilder b = new StringBuilder(camelKey.length() + 4);
    for (char ch : camelKey.toCharArray()) {
        if (Character.isUpperCase(ch)) {
            b.append('.').append(Character.toLowerCase(ch));
        } else {/*from  w  w  w . j  av a  2s.c  o m*/
            b.append(ch);
        }
    }
    return b.toString();
}

From source file:org.apache.struts2.convention.DefaultActionNameBuilder.java

public String build(String className) {
    String actionName = className;

    // Truncate Action suffix if found
    if (actionName.endsWith(actionSuffix)) {
        actionName = actionName.substring(0, actionName.length() - actionSuffix.length());
    }/*from   ww w . ja  va 2 s. c om*/

    // Force initial letter of action to lowercase, if desired
    if ((lowerCase) && (actionName.length() > 1)) {
        int lowerPos = actionName.lastIndexOf('/') + 1;
        StringBuilder sb = new StringBuilder();
        sb.append(actionName.substring(0, lowerPos));
        sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
        sb.append(actionName.substring(lowerPos + 1));
        actionName = sb.toString();
    }

    return actionName;
}

From source file:org.cruxframework.crux.core.rebind.datasource.DataSources.java

/**
 * /*from w  w  w .j a  va  2s .c o  m*/
 */
@SuppressWarnings("unchecked")
protected static void initializeDataSources() {
    dataSourcesCanonicalNames = new HashMap<String, Map<String, String>>();
    dataSourcesClassNames = new HashMap<String, Map<String, String>>();
    Set<String> dataSourceNames = ClassScanner.searchClassesByInterface(DataSource.class);
    if (dataSourceNames != null) {
        for (String dataSource : dataSourceNames) {
            try {
                Class<? extends DataSource<?>> dataSourceClass = (Class<? extends DataSource<?>>) Class
                        .forName(dataSource);
                org.cruxframework.crux.core.client.datasource.annotation.DataSource annot = dataSourceClass
                        .getAnnotation(
                                org.cruxframework.crux.core.client.datasource.annotation.DataSource.class);
                if (annot != null) {
                    Device[] devices = annot.supportedDevices();
                    String resourceKey = annot.value();
                    if (devices == null || devices.length == 0) {
                        addResource(dataSourceClass, resourceKey, Device.all);
                    } else {
                        for (Device device : devices) {
                            addResource(dataSourceClass, resourceKey, device);
                        }
                    }
                } else {
                    String simpleName = dataSourceClass.getSimpleName();
                    if (simpleName.length() > 1) {
                        simpleName = Character.toLowerCase(simpleName.charAt(0)) + simpleName.substring(1);
                    } else {
                        simpleName = simpleName.toLowerCase();
                    }
                    addResource(dataSourceClass, simpleName, Device.all);
                }
            } catch (Throwable e) {
                logger.error("Error initializing datasource.", e);
            }
        }
    }
}

From source file:org.apache.velocity.runtime.parser.node.PropertyExecutor.java

/**
 * @param clazz// w  ww.j  ava2  s  .c o m
 * @param property
 */
protected void discover(final Class clazz, final String property) {
    /*
     *  this is gross and linear, but it keeps it straightforward.
     */

    try {
        Object[] params = {};

        StringBuffer sb = new StringBuffer("get");
        sb.append(property);

        setMethod(introspector.getMethod(clazz, sb.toString(), params));

        if (!isAlive()) {
            /*
             *  now the convenience, flip the 1st character
             */

            char c = sb.charAt(3);

            if (Character.isLowerCase(c)) {
                sb.setCharAt(3, Character.toUpperCase(c));
            } else {
                sb.setCharAt(3, Character.toLowerCase(c));
            }

            setMethod(introspector.getMethod(clazz, sb.toString(), params));
        }
    }
    /**
     * pass through application level runtime exceptions
     */
    catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Exception while looking for property getter for '" + property;
        Logger.error(this, msg, e);
        throw new VelocityException(msg, e);
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static String camelCaseToWords(String s) {
    if (s == null) {
        return null;
    }//from  ww  w .j  av a2s. c o  m
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (first) {
            first = false;
            sb.append(c);
        } else {
            if (Character.isUpperCase(c)) {
                sb.append(' ');
                sb.append(Character.toLowerCase(c));
            } else {
                sb.append(c);
            }
        }
    }
    return sb.toString();
}

From source file:agilejson.JSON.java

public static String deCamelCase(String s) {
    Matcher m = decamelcasePattern.matcher(s.substring(1));
    if (!m.find()) {
        return s.toLowerCase();
    }//from  ww  w. j  a va2 s . c o  m

    String res = String.valueOf(Character.toLowerCase(s.charAt(0)));
    int lastEnd;
    while (true) {
        res += m.group(1);
        res += "_" + m.group(2).toLowerCase();
        lastEnd = m.end();
        if (!m.find()) {
            return res + s.substring(lastEnd + 1);
        }
    }
}

From source file:br.com.bropenmaps.util.Util.java

/**
 * Desfaz as alteraes feitas quando um termo precisa ser modificado ao ser utilizado como parmetro em requisies HTTP (decoder para o {@link URLEncoder}).
 * Este mtodo transforma '+' em espao./*from   ww  w  .  j a va 2  s . c  om*/
 * @param s - termo a ser modificado 
 * @return Retorna o termo com as modificaes realizadas
 */
public static String unescape(String s) {
    if (s == null) {
        return s;
    }

    StringBuffer sbuf = new StringBuffer();
    int l = s.length();
    int ch = -1;
    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); // Aarg0dd 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:edu.ksu.cis.santos.mdcf.dml.ast.AstNode.java

private void toString(final StringBuilder sb, final Object o) {
    if (o instanceof AstNode) {
        final AstNode n = (AstNode) o;
        final String name = n.getClass().getSimpleName();
        sb.append(Character.toLowerCase(name.charAt(0)));
        sb.append(name.substring(1));// ww  w  . j a  v  a 2  s  . com
        sb.append('(');
        final Object[] children = n.children();
        final int len = children.length;
        for (int i = 0; i < len; i++) {
            toString(sb, children[i]);
            if (i != (len - 1)) {
                sb.append(", ");
            }
        }
        sb.append(')');
    } else if (o instanceof List) {
        final List<?> l = (List<?>) o;
        sb.append("list(");
        final int size = l.size();
        for (int i = 0; i < size; i++) {
            toString(sb, l.get(i));
            if (i != (size - 1)) {
                sb.append(", ");
            }
        }
        sb.append(')');
    } else if (o instanceof Optional) {
        final Optional<?> opt = (Optional<?>) o;
        if (opt.isPresent()) {
            sb.append("some(");
            toString(sb, opt.get());
            sb.append(')');
        } else {
            sb.append("none()");
        }
    } else if (o instanceof String) {
        final String s = (String) o;
        sb.append('"');
        sb.append(StringEscapeUtils.escapeJava(s));
        sb.append('"');
    } else if (o instanceof Enum) {
        final Enum<?> e = (Enum<?>) o;
        sb.append(e.getClass().getSimpleName());
        sb.append('.');
        sb.append(e.toString());
    } else {
        sb.append(o);
    }
}