This commit is contained in:
looly
2022-01-05 18:45:45 +08:00
parent 24569b81c8
commit f8017c31d5
4 changed files with 17 additions and 7 deletions

View File

@@ -90,7 +90,7 @@ public class NamingCase {
} else if (Character.isLowerCase(preChar)) {
// 前一个为小写
sb.append(symbol);
if (null == nextChar || Character.isLowerCase(nextChar)) {
if (null == nextChar || Character.isLowerCase(nextChar) || CharUtil.isNumber(nextChar)) {
//普通首字母大写如aBcc -> a_bcc
c = Character.toLowerCase(c);
}

View File

@@ -0,0 +1,15 @@
package cn.hutool.core.text;
import cn.hutool.core.lang.Dict;
import org.junit.Assert;
import org.junit.Test;
public class NamingCaseTest {
@Test
public void toUnderlineCaseTest(){
// https://github.com/dromara/hutool/issues/2070
Dict.create()
.set("customerNickV2", "customer_nick_v2")
.forEach((key, value) -> Assert.assertEquals(value, NamingCase.toUnderlineCase(key)));
}
}

View File

@@ -421,12 +421,6 @@ public class StrUtilTest {
.set("HelloWorld_test", "hello_world_test")
.set("H2", "H2")
.set("H#case", "H#case")
.forEach((key, value) -> Assert.assertEquals(value, StrUtil.toUnderlineCase(key)));
}
@Test
public void toUnderLineCaseTest2() {
Dict.create()
.set("PNLabel", "PN_label")
.forEach((key, value) -> Assert.assertEquals(value, StrUtil.toUnderlineCase(key)));
}