Skip to content

Commit

Permalink
refactor: fix template
Browse files Browse the repository at this point in the history
  • Loading branch information
wodiwudi committed Sep 4, 2024
1 parent 68aa5d2 commit e9b3615
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
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();
}
}
2 changes: 1 addition & 1 deletion jcommon/codegen/src/main/resources/tlp/testSpring.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ${testName} {


@Resource
private ${serviceName} ${strutil.toLowerCase(serviceName)}Service;
private ${serviceName} ${className}Service;


}
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);
}


}

0 comments on commit e9b3615

Please sign in to comment.