Java String Camel Case To camelhumpToUnderline(String str)

Here you can find the source of camelhumpToUnderline(String str)

Description

camelhump To Underline

License

Apache License

Declaration

public static String camelhumpToUnderline(String str) 

Method Source Code

//package com.java2s;
/*// www.jav a 2 s .  c  o m
 * Copyright (c) 2016 yunmle.com(????????).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */

public class Main {

    public static String camelhumpToUnderline(String str) {
        final int size;
        final char[] chars;
        final StringBuilder sb = new StringBuilder((size = (chars = str.toCharArray()).length) * 3 / 2 + 1);
        char c;
        for (int i = 0; i < size; i++) {
            c = chars[i];
            if (isLowercaseAlpha(c)) {
                sb.append(toUpperAscii(c));
            } else {
                sb.append('_').append(c);
            }
        }
        return sb.charAt(0) == '_' ? sb.substring(1) : sb.toString();
    }

    public static boolean isLowercaseAlpha(char c) {
        return (c >= 'a') && (c <= 'z');
    }

    public static char toUpperAscii(char c) {
        if (isLowercaseAlpha(c)) {
            c -= (char) 0x20;
        }
        return c;
    }
}

Related

  1. camelcaseToUppercase(String camelCase)
  2. camelCaseToWords(String data)
  3. camelCaseUnderscores(String str)
  4. camelHump(String str)
  5. camelHumpsToWords(String camelHumps)
  6. camelizeOneWord(String word, boolean firstLetterInLowerCase)
  7. camelPrefix(String str, int prefixSize)
  8. camelToComposite(String camel)
  9. camelToFixedString(String str, String fixed)