Skip to content

Commit 2d88ce4

Browse files
committed
fix 首字母大写时候没有转小写
1 parent 179479f commit 2d88ce4

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/main/java/com/crzsc/plugin/utils/FileGenerator.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.crzsc.plugin.utils
22

33
import com.crzsc.plugin.utils.PluginUtils.showNotify
44
import com.crzsc.plugin.utils.PluginUtils.toLowCamelCase
5-
import com.crzsc.plugin.utils.PluginUtils.toUpperCaseFirst
5+
import com.crzsc.plugin.utils.PluginUtils.upperCaseFirst
66
import com.intellij.openapi.application.ApplicationManager
77
import com.intellij.openapi.command.WriteCommandAction
88
import com.intellij.openapi.project.Project
@@ -140,9 +140,9 @@ class FileGenerator(private val project: Project) {
140140
val value = it.path.removePrefix("$basePath/")
141141
if (namedWithParent) {
142142
it.parent?.let { parent ->
143-
key = "${parent.name.toLowCamelCase(regex)}${key.toUpperCaseFirst()}"
143+
key = "${parent.name.toLowCamelCase(regex)}${key.upperCaseFirst()}"
144144
if (map.containsKey(key)) {
145-
key = "${parent.parent.name.toLowCamelCase(regex)}${key.toUpperCaseFirst()}"
145+
key = "${parent.parent.name.toLowCamelCase(regex)}${key.upperCaseFirst()}"
146146
}
147147
map[key] = value
148148
}

src/main/java/com/crzsc/plugin/utils/PluginUtils.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ object PluginUtils {
4242
val sb = StringBuilder()
4343
for (i in split.indices) {
4444
if (i == 0) {
45-
sb.append(split[i])
45+
sb.append(split[i].lowerCaseFirst())
4646
} else {
47-
sb.append(split[i].toUpperCaseFirst())
47+
sb.append(split[i].upperCaseFirst())
4848
}
4949
}
5050
return sb.toString()
@@ -59,14 +59,22 @@ object PluginUtils {
5959
.openTextEditor(OpenFileDescriptor(project, vFile), true)
6060
}
6161

62+
fun String.lowerCaseFirst(): String {
63+
return if (this.isEmpty()) {
64+
this
65+
} else {
66+
"${this[0].lowercase()}${this.subSequence(1, this.length)}"
67+
}
68+
}
69+
6270
/**
6371
* 首字母大写
6472
*/
65-
fun String.toUpperCaseFirst(): String {
73+
fun String.upperCaseFirst(): String {
6674
return if (this.isEmpty()) {
6775
this
6876
} else {
69-
"${this[0].toUpperCase()}${this.subSequence(1, this.length)}"
77+
"${this[0].uppercase()}${this.subSequence(1, this.length)}"
7078
}
7179
}
7280
}

0 commit comments

Comments
 (0)