mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
toCamelCase 转换逻辑修改
This commit is contained in:
parent
edada89d64
commit
db0c9dd497
@ -175,7 +175,12 @@ public class NamingCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* 将连接符方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。
|
||||
* 将连接符方式命名的字符串转换为驼峰式。如果转换前的下划线大写方式命名的字符串为空,则返回空字符串。<br>
|
||||
* 当otherCharToLower为{@code true}时,分为以下情况:
|
||||
* <ul>
|
||||
* <li>如果给定字符串全部为大写,转换为小写,如NAME转为name。</li>
|
||||
* <li>如果给定字符串大小写混合,认定为字符串已经是驼峰模式,只小写首字母,如TableName转换为tableName。</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param name 转换前的自定义方式命名的字符串
|
||||
* @param symbol 原字符串中的连接符连接符
|
||||
@ -206,6 +211,13 @@ public class NamingCase {
|
||||
}
|
||||
return sb.toString();
|
||||
} else {
|
||||
if(otherCharToLower){
|
||||
if(StrUtil.isUpperCase(name2)){
|
||||
return name2.toLowerCase();
|
||||
}
|
||||
return StrUtil.lowerFirst(name2);
|
||||
}
|
||||
|
||||
return name2;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2023. looly(loolly@aliyun.com)
|
||||
* Hutool is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* https://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
package org.dromara.hutool.core.map;
|
||||
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Issue3340Test {
|
||||
@Test
|
||||
void toCamelCaseMapTest() {
|
||||
final Map<String, Object> map = new HashMap<>();
|
||||
map.put("ID","1");
|
||||
map.put("NAME","2");
|
||||
map.put("STU_ID","3");
|
||||
final Map<String, Object> map1 = MapUtil.toCamelCaseMap(map);
|
||||
|
||||
Assertions.assertEquals("2", map1.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void toCamelCaseTest() {
|
||||
final String str = "ID";
|
||||
Assertions.assertEquals("id", StrUtil.toCamelCase(str));
|
||||
}
|
||||
}
|
@ -22,7 +22,7 @@ public class NamingCaseTest {
|
||||
public void toCamelCaseTest() {
|
||||
Dict.of()
|
||||
.set("Table_Test_Of_day","tableTestOfDay")
|
||||
.set("TableTestOfDay","TableTestOfDay")
|
||||
.set("TableTestOfDay","tableTestOfDay")
|
||||
.set("abc_1d","abc1d")
|
||||
.forEach((key, value) -> Assertions.assertEquals(value, NamingCase.toCamelCase(key)));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user