-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update * refactor codegen * change pom * change infra pom * change template * refactor: fix template
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
jcommon/codegen/src/main/java/run/mone/ai/codegen/util/StrUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package run.mone.ai.codegen.util; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
/** | ||
* @author zhangxiaowei6 | ||
* @Date 2024/9/4 16:31 | ||
*/ | ||
|
||
@Slf4j | ||
public class StrUtil { | ||
|
||
public static String toCamelCase(String input) { | ||
if (input == null || input.isEmpty()) { | ||
return input; | ||
} | ||
|
||
StringBuilder result = new StringBuilder(); | ||
boolean capitalizeNext = false; | ||
|
||
for (int i = 0; i < input.length(); i++) { | ||
char currentChar = input.charAt(i); | ||
|
||
if (currentChar == ' ') { | ||
capitalizeNext = true; | ||
} else { | ||
if (capitalizeNext) { | ||
result.append(Character.toUpperCase(currentChar)); | ||
capitalizeNext = false; | ||
} else { | ||
result.append(Character.toLowerCase(currentChar)); | ||
} | ||
} | ||
} | ||
|
||
// 确保第一个字符是小写的 | ||
if (result.length() > 0) { | ||
result.setCharAt(0, Character.toLowerCase(result.charAt(0))); | ||
} | ||
|
||
return result.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
jcommon/codegen/src/test/java/com/xiaomi/youpin/codegen/test/StrTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.xiaomi.youpin.codegen.test; | ||
|
||
import org.junit.Test; | ||
import run.mone.ai.codegen.util.StrUtil; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
|
||
public class StrTest { | ||
|
||
|
||
|
||
|
||
@Test | ||
public void testToCamelCase() { | ||
String input = "hello world"; | ||
String expected = "helloWorld"; | ||
String actual = StrUtil.toCamelCase(input); | ||
assertEquals(expected, actual); | ||
|
||
input = "java programming language"; | ||
expected = "javaProgrammingLanguage"; | ||
actual = StrUtil.toCamelCase(input); | ||
assertEquals(expected, actual); | ||
|
||
input = " leading and trailing spaces "; | ||
expected = "leadingAndTrailingSpaces"; | ||
actual = StrUtil.toCamelCase(input); | ||
assertEquals(expected, actual); | ||
|
||
input = ""; | ||
expected = ""; | ||
actual = StrUtil.toCamelCase(input); | ||
assertEquals(expected, actual); | ||
|
||
input = null; | ||
expected = null; | ||
actual = StrUtil.toCamelCase(input); | ||
assertEquals(expected, actual); | ||
} | ||
|
||
|
||
} |