This commit is contained in:
Looly 2023-03-31 13:35:18 +08:00
parent f79dd096e2
commit 06c27a8cfe
2 changed files with 22 additions and 1 deletions

View File

@ -173,6 +173,18 @@ public class NamingCase {
* @since 5.7.17
*/
public static String toCamelCase(final CharSequence name, final char symbol) {
return toCamelCase(name, symbol, true);
}
/**
* 将连接符方式命名的字符串转换为驼峰式如果转换前的下划线大写方式命名的字符串为空则返回空字符串
*
* @param name 转换前的自定义方式命名的字符串
* @param symbol 原字符串中的连接符连接符
* @param otherCharToLower 其他非连接符后的字符是否需要转为小写
* @return 转换后的驼峰式命名的字符串
*/
public static String toCamelCase(final CharSequence name, final char symbol, final boolean otherCharToLower) {
if (null == name) {
return null;
}
@ -191,7 +203,7 @@ public class NamingCase {
sb.append(Character.toUpperCase(c));
upperCase = false;
} else {
sb.append(Character.toLowerCase(c));
sb.append(otherCharToLower ? Character.toLowerCase(c) : c);
}
}
return sb.toString();

View File

@ -47,4 +47,13 @@ public class NamingCaseTest {
// https://gitee.com/dromara/hutool/issues/I5TVMU
Assertions.assertEquals("t1C1", NamingCase.toUnderlineCase("t1C1"));
}
@Test
public void issue3031Test() {
String camelCase = NamingCase.toCamelCase("user_name,BIRTHDAY");
Assertions.assertEquals("userName,birthday", camelCase);
camelCase = NamingCase.toCamelCase("user_name,BIRTHDAY", '_', false);
Assertions.assertEquals("userName,BIRTHDAY", camelCase);
}
}