Skip to content

Commit 98c86e7

Browse files
authored
Add pascalCaseName and leftPadZeros.
Add pascalCaseName and leftPadZeros.
2 parents 68d35f2 + 32dd7cc commit 98c86e7

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/main/java/com/shuzijun/leetcode/plugin/utils/VelocityTool.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,46 @@ public class VelocityTool extends StringUtils {
99

1010
private static String[] numsAry = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
1111

12+
public static String leftPadZeros(String s, int resultLength) {
13+
if (s.length() >= resultLength) {
14+
return s;
15+
}
16+
int nPads = resultLength - s.length();
17+
StringBuilder sb = new StringBuilder();
18+
for (int i = 0; i < nPads; ++i) {
19+
sb.append('0');
20+
}
21+
sb.append(s);
22+
return sb.toString();
23+
}
24+
25+
public static String pascalCaseName(String underscoreName) {
26+
if (isNotBlank(underscoreName)) {
27+
underscoreName = underscoreName.replace(" ", "_");
28+
StringBuilder result = new StringBuilder();
29+
if (isNumeric(underscoreName.substring(0, 1))) {
30+
underscoreName = numsAry[Integer.valueOf(underscoreName.substring(0, 1))] + "-" + underscoreName.substring(1);
31+
}
32+
boolean flag = false;
33+
for (int i = 0; i < underscoreName.length(); i++) {
34+
char ch = underscoreName.charAt(i);
35+
if ('_' == ch || '-' == ch) {
36+
flag = true;
37+
} else {
38+
if (flag) {
39+
result.append(Character.toUpperCase(ch));
40+
flag = false;
41+
} else {
42+
result.append(ch);
43+
}
44+
}
45+
}
46+
return result.toString();
47+
} else {
48+
return underscoreName;
49+
}
50+
}
51+
1252
public static String camelCaseName(String underscoreName) {
1353

1454
if (isNotBlank(underscoreName)) {

src/main/resources/i18n/info.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ report=Report to plugin developer
3434
donate.info=Donation
3535
updata=Leetcode Editor new version {0} is found. Please update the plugin
3636
user.email=YOU HAVE NOT VERIFIED YOUR ACCOUNT\nYou cannot submit your code to the judge system until you verify your email.\nYou may resend the verification email or change your email in your profile page.
37-
template.variable=${0}question.title{1}\tquestion title\tex:Two Sum\n${0}question.titleSlug{1}\tquestion title slug \tex:two-sum\n${0}question.frontendQuestionId{1}\tquestion serial number\n${0}question.content{1}\tquestion content\n${0}question.code{1}\tquestion code\n$!velocityTool.camelCaseName(str)\ttransform str camel case\n$!velocityTool.snakeCaseName(str)\ttransform str snake case
37+
template.variable=${0}question.title{1}\tquestion title\tex:Two Sum\n${0}question.titleSlug{1}\tquestion title slug \tex:two-sum\n${0}question.frontendQuestionId{1}\tquestion serial number\n${0}question.content{1}\tquestion content\n${0}question.code{1}\tquestion code\n$!velocityTool.camelCaseName(str)\ttransform str camel case\n$!velocityTool.snakeCaseName(str)\ttransform str snake case\n$!velocityTool.pascalCaseName(str)\ttransform str pascal case\n$!velocityTool.leftPadZeros(str,n)\tpad sting with zero make str length at least n.
3838
tree.load=Please load questions first
3939
tree.null=Questions returned are empty
4040
tree.select=Please select a valid question in the list

src/main/resources/i18n/info_zh.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ report=\u5411\u63D2\u4EF6\u4F5C\u8005\u62A5\u544A
3434
donate.info=\u6253\u8D4F
3535
updata=leetcode editor\u65B0\u7248\u672C {0} \u53D1\u5E03,\u8BF7\u53CA\u65F6\u66F4\u65B0
3636
user.email=\u60A8\u5C1A\u672A\u9A8C\u8BC1\u81EA\u5DF1\u7684\u5E10\u6237\n\u5728\u9A8C\u8BC1\u7535\u5B50\u90AE\u4EF6\u4E4B\u524D\uFF0C\u60A8\u65E0\u6CD5\u5C06\u4EE3\u7801\u63D0\u4EA4\u7ED9\u8BC4\u5224\u7CFB\u7EDF\u3002\n\u60A8\u53EF\u4EE5\u5728\u4E2A\u4EBA\u8D44\u6599\u9875\u9762\u4E2D\u91CD\u65B0\u53D1\u9001\u9A8C\u8BC1\u7535\u5B50\u90AE\u4EF6\u6216\u66F4\u6539\u7535\u5B50\u90AE\u4EF6\u3002
37-
template.variable=${0}question.title{1}\t\u9898\u76EE\u6807\u9898\t\u793A\u4F8B:\u4E24\u6570\u4E4B\u548C\n${0}question.titleSlug{1}\t\u9898\u76EE\u6807\u8BB0\t\u793A\u4F8B:two-sum\n${0}question.frontendQuestionId{1}\t\u9898\u76EE\u7F16\u53F7\n${0}question.content{1}\t\u9898\u76EE\u63CF\u8FF0\n${0}question.code{1}\t\u9898\u76EE\u4EE3\u7801\n$!velocityTool.camelCaseName(str)\t\u8F6C\u6362\u5B57\u7B26\u4E3A\u9A7C\u5CF0\u6837\u5F0F\n$!velocityTool.snakeCaseName(str)\t\u8F6C\u6362\u5B57\u7B26\u4E3A\u86C7\u5F62\u6837\u5F0F
37+
template.variable=${0}question.title{1}\t\u9898\u76EE\u6807\u9898\t\u793A\u4F8B:\u4E24\u6570\u4E4B\u548C\n${0}question.titleSlug{1}\t\u9898\u76EE\u6807\u8BB0\t\u793A\u4F8B:two-sum\n${0}question.frontendQuestionId{1}\t\u9898\u76EE\u7F16\u53F7\n${0}question.content{1}\t\u9898\u76EE\u63CF\u8FF0\n${0}question.code{1}\t\u9898\u76EE\u4EE3\u7801\n$!velocityTool.camelCaseName(str)\t\u8F6C\u6362\u5B57\u7B26\u4E3A\u9A7C\u5CF0\u6837\u5F0F\n$!velocityTool.snakeCaseName(str)\t\u8F6C\u6362\u5B57\u7B26\u4E3A\u86C7\u5F62\u6837\u5F0F\n$!velocityTool.pascalCaseName(str)\ttransform str pascal case\n$!velocityTool.leftPadZeros(str,n)\tpad sting with zero make str length at least n.
3838
tree.load=\u8BF7\u5148\u52A0\u8F7D\u9898\u76EE
3939
tree.null=\u83B7\u53D6\u9898\u76EE\u4E3A\u7A7A
4040
tree.select=\u8BF7\u5728\u5217\u8868\u4E2D\u9009\u62E9\u4E00\u4E2A\u6709\u6548\u7684\u9898\u76EE

0 commit comments

Comments
 (0)