/**
* 将驼峰式命名的字符串转换为下划线大写方式。如果转换前的驼峰式命名的字符串为空,则返回空字符串。</br>
* 例如:HelloWorld->HELLO_WORLD
* @param name 转换前的驼峰式命名的字符串
* @return 转换后下划线大写方式命名的字符串
*/
public static String underscoreNameUpperCase(String name) {
StringBuilder result = new StringBuilder();
if (name != null && () > 0) {
// 将第一个字符处理成大写
((0, 1).toUpperCase());
// 循环处理其余字符
for (int i = 1; i < (); i++) {
String s = (i, i + 1);
// 在大写字母前添加下划线
if ((()) && !((0))) {
("_");
}
// 其他字符直接转成大写
(());
}
}
return ();
}
/**
* 将下划线大写方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。</br>
* 例如:HELLO_WORLD->HelloWorld
* @param name 转换前的下划线大写方式命名的字符串
* @return 转换后的驼峰式命名的字符串
*/
public static String camelName(String name) {
StringBuilder result = new StringBuilder();
// 快速检查
if (name == null || ("")) {
// 没必要转换
return "";
} else if (!("_")) {
// 不含下划线,仅将首字母小写
return (0, 1).toLowerCase() + (1);
}
// 用下划线将原始字符串分割
String camels[] = ("_");
for (String camel : camels) {
// 跳过原始字符串中开头、结尾的下换线或双重下划线
if (("")) {
continue;
}
// 处理真正的驼峰片段
if (() == 0) {
// 第一个驼峰片段,全部字母都小写
(());
} else {
// 其他的驼峰片段,首字母大写
((0, 1).toUpperCase());
((1).toLowerCase());
}
}
return ();
}