fix: 正常に絵文字が出力されない問題を修正2
This commit is contained in:
parent
7d1063b0c3
commit
28d3c78172
|
@ -9,12 +9,4 @@ repositories {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(gradleApi())
|
compileOnly(gradleApi())
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
|
}
|
||||||
implementation("io.ktor:ktor-client-core:2.2.3")
|
|
||||||
implementation("io.ktor:ktor-client-cio:2.2.3")
|
|
||||||
}
|
|
||||||
|
|
||||||
buildscript {
|
|
||||||
|
|
||||||
}
|
|
||||||
ext["kotlin_version"] = "1.8.10"
|
|
|
@ -17,153 +17,150 @@ class EmojiPlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
project.task("generateEmoji")
|
project.task("generateEmoji")
|
||||||
.doLast(Action {
|
.doLast(Action {
|
||||||
runBlocking {
|
val httpClient = HttpClient.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_1_1)
|
||||||
|
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||||
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val req = HttpRequest
|
||||||
|
.newBuilder(URI.create("https://unicode.org/Public/emoji/15.1/emoji-test.txt"))
|
||||||
|
.GET()
|
||||||
|
.setHeader(
|
||||||
|
"User-Agent",
|
||||||
|
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.3"
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
|
||||||
val httpClient = HttpClient.newBuilder()
|
val bodyAsText = httpClient.send(req, HttpResponse.BodyHandlers.ofString()).body()
|
||||||
.version(HttpClient.Version.HTTP_1_1)
|
|
||||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
|
||||||
.connectTimeout(Duration.ofSeconds(10))
|
|
||||||
.build()
|
|
||||||
|
|
||||||
val req = HttpRequest
|
println(project.buildDir.path)
|
||||||
.newBuilder(URI.create("https://unicode.org/Public/emoji/15.1/emoji-test.txt"))
|
|
||||||
.GET()
|
|
||||||
.setHeader(
|
|
||||||
"User-Agent",
|
|
||||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.3"
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
|
|
||||||
|
|
||||||
val bodyAsText = httpClient.send(req, HttpResponse.BodyHandlers.ofString()).body()
|
|
||||||
|
|
||||||
println(project.buildDir.path)
|
|
||||||
// println(bodyAsText)
|
// println(bodyAsText)
|
||||||
|
|
||||||
val file =
|
val file =
|
||||||
project.layout.buildDirectory.file("generated/source/emoji/main/kotlin/Emojis.kt")
|
project.layout.buildDirectory.file("generated/source/emoji/main/kotlin/Emojis.kt")
|
||||||
val asFile = file.get().asFile
|
val asFile = file.get().asFile
|
||||||
asFile.parentFile.mkdirs()
|
asFile.parentFile.mkdirs()
|
||||||
val split = bodyAsText.replace("\r", "").split("\n");
|
val split = bodyAsText.replace("\r", "").split("\n");
|
||||||
|
|
||||||
println(split.size)
|
println(split.size)
|
||||||
|
|
||||||
var group: String = ""
|
var group: String = ""
|
||||||
var subgroup: String = ""
|
var subgroup: String = ""
|
||||||
|
|
||||||
var emojiCount = 0
|
var emojiCount = 0
|
||||||
var groupCount = 0
|
var groupCount = 0
|
||||||
|
|
||||||
data class Emoji(val group: String, val value: String)
|
data class Emoji(val group: String, val value: String)
|
||||||
|
|
||||||
val enumList = mutableMapOf<String, Emoji>()
|
val enumList = mutableMapOf<String, Emoji>()
|
||||||
//TODO グループ分けしたことで重複がなくなるはずなので修正
|
//TODO グループ分けしたことで重複がなくなるはずなので修正
|
||||||
for (s in split) {
|
for (s in split) {
|
||||||
if (emojiCount >= 99) {
|
if (emojiCount >= 99) {
|
||||||
emojiCount = 0
|
emojiCount = 0
|
||||||
groupCount++
|
groupCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
s.startsWith("# group:") -> {
|
||||||
|
group = s.substringAfter(": ")
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
s.startsWith("# subgroup:") -> {
|
||||||
s.startsWith("# group:") -> {
|
subgroup = s.substringAfter(": ")
|
||||||
group = s.substringAfter(": ")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
s.startsWith("# subgroup:") -> {
|
s.isNullOrBlank() -> {}
|
||||||
subgroup = s.substringAfter(": ")
|
s.startsWith("#") -> {}
|
||||||
}
|
else -> {
|
||||||
|
val description = s.substringAfterLast("E").substringAfter(" ")
|
||||||
|
val status = s.substringAfter(";").substringBefore("#").trim()
|
||||||
|
|
||||||
s.isNullOrBlank() -> {}
|
val code =
|
||||||
s.startsWith("#") -> {}
|
s.substringBefore(";").replace(Regex(" +"), " ").trim()
|
||||||
else -> {
|
val char = s.substringAfter("# ").substringBefore(" ").trim()
|
||||||
val description = s.substringAfterLast("E").substringAfter(" ")
|
|
||||||
val status = s.substringAfter(";").substringBefore("#").trim()
|
|
||||||
|
|
||||||
val code =
|
val statusString = when (status) {
|
||||||
s.substringBefore(";").replace(Regex(" +"), " ").trim()
|
"fully-qualified" -> "Status.FULLY_QUALIFIED"
|
||||||
val char = s.substringAfter("# ").substringBefore(" ").trim()
|
"unqualified" -> "Status.UNAUALIFIED"
|
||||||
|
"minimally-qualified" -> "Status.MINIMALLY_QUALIFIED"
|
||||||
|
|
||||||
val statusString = when (status) {
|
else -> {
|
||||||
"fully-qualified" -> "Status.FULLY_QUALIFIED"
|
println(status)
|
||||||
"unqualified" -> "Status.UNAUALIFIED"
|
continue
|
||||||
"minimally-qualified" -> "Status.MINIMALLY_QUALIFIED"
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
println(status)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enumList.putIfAbsent(
|
|
||||||
description,
|
|
||||||
Emoji(
|
|
||||||
group + groupCount,
|
|
||||||
"${
|
|
||||||
(description + "_" + status).toUpperCase()
|
|
||||||
.replace(" ", "_")
|
|
||||||
.replace("-", "_")
|
|
||||||
.replace(":", "_")
|
|
||||||
.replace(",", "_")
|
|
||||||
.replace(".", "_")
|
|
||||||
.replace("’", "_")
|
|
||||||
.replace("1ST", "FIRST")
|
|
||||||
.replace("2ND", "SECOND")
|
|
||||||
.replace("3RD", "THIRD")
|
|
||||||
.replace("!", "_EXCLAMATION_MARK_")
|
|
||||||
.replace("#", "SHARP")
|
|
||||||
.replace("*", "ASTRISC")
|
|
||||||
.replace("0", "ZERO")
|
|
||||||
.replace("1", "ONE")
|
|
||||||
.replace("2", "TWO")
|
|
||||||
.replace("3", "THREE")
|
|
||||||
.replace("4", "FOUR")
|
|
||||||
.replace("5", "FIVE")
|
|
||||||
.replace("6", "SIX")
|
|
||||||
.replace("7", "SEVEN")
|
|
||||||
.replace("8", "EIGHT")
|
|
||||||
.replace("9", "NINE")
|
|
||||||
.replace("“", "_")
|
|
||||||
.replace("”", "_")
|
|
||||||
.replace("(", "_")
|
|
||||||
.replace(")", "_")
|
|
||||||
.replace("&", "_AND_")
|
|
||||||
.replace("Ã", "A")
|
|
||||||
.replace("É", "E")
|
|
||||||
.replace("Í", "I")
|
|
||||||
.replace("Ñ", "N")
|
|
||||||
.replace("Å", "A")
|
|
||||||
.replace("Ô", "O")
|
|
||||||
.replace("Ç", "C")
|
|
||||||
.replace(Regex("_+"), "_")
|
|
||||||
}(\"$group\",\"$subgroup\",\"$code\",\"$char\",\"$description\",$statusString)"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
emojiCount++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enumList.putIfAbsent(
|
||||||
|
(description + "_" + status),
|
||||||
|
Emoji(
|
||||||
|
group + groupCount,
|
||||||
|
"${
|
||||||
|
(description + "_" + status).toUpperCase()
|
||||||
|
.replace(" ", "_")
|
||||||
|
.replace("-", "_")
|
||||||
|
.replace(":", "_")
|
||||||
|
.replace(",", "_")
|
||||||
|
.replace(".", "_")
|
||||||
|
.replace("’", "_")
|
||||||
|
.replace("1ST", "FIRST")
|
||||||
|
.replace("2ND", "SECOND")
|
||||||
|
.replace("3RD", "THIRD")
|
||||||
|
.replace("!", "_EXCLAMATION_MARK_")
|
||||||
|
.replace("#", "SHARP")
|
||||||
|
.replace("*", "ASTRISC")
|
||||||
|
.replace("0", "ZERO")
|
||||||
|
.replace("1", "ONE")
|
||||||
|
.replace("2", "TWO")
|
||||||
|
.replace("3", "THREE")
|
||||||
|
.replace("4", "FOUR")
|
||||||
|
.replace("5", "FIVE")
|
||||||
|
.replace("6", "SIX")
|
||||||
|
.replace("7", "SEVEN")
|
||||||
|
.replace("8", "EIGHT")
|
||||||
|
.replace("9", "NINE")
|
||||||
|
.replace("“", "_")
|
||||||
|
.replace("”", "_")
|
||||||
|
.replace("(", "_")
|
||||||
|
.replace(")", "_")
|
||||||
|
.replace("&", "_AND_")
|
||||||
|
.replace("Ã", "A")
|
||||||
|
.replace("É", "E")
|
||||||
|
.replace("Í", "I")
|
||||||
|
.replace("Ñ", "N")
|
||||||
|
.replace("Å", "A")
|
||||||
|
.replace("Ô", "O")
|
||||||
|
.replace("Ç", "C")
|
||||||
|
.replace(Regex("_+"), "_")
|
||||||
|
}(\"$group\",\"$subgroup\",\"$code\",\"$char\",\"$description\",$statusString)"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
emojiCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val emojis = mutableMapOf<String, MutableList<Emoji>>()
|
}
|
||||||
enumList.values.forEach {
|
val emojis = mutableMapOf<String, MutableList<Emoji>>()
|
||||||
emojis.getOrPut(
|
enumList.values.forEach {
|
||||||
it.group.replace(" ", "").replace("&", "And")
|
emojis.getOrPut(
|
||||||
) { mutableListOf() }.add(it)
|
it.group.replace(" ", "").replace("&", "And")
|
||||||
}
|
) { mutableListOf() }.add(it)
|
||||||
|
}
|
||||||
|
|
||||||
val map = emojis.map {
|
val map = emojis.map {
|
||||||
"enum class ${it.key}(override val group:String,override val subgroup:String,override val code:String,override val char:String,override val description:String,val status:Status):UnicodeEmoji{\n" +
|
"enum class ${it.key}(override val group:String,override val subgroup:String,override val code:String,override val char:String,override val description:String,val status:Status):UnicodeEmoji{\n" +
|
||||||
"${
|
"${
|
||||||
it.value.map { it.value }.joinToString(
|
it.value.map { it.value }.joinToString(
|
||||||
",\n"
|
",\n"
|
||||||
)
|
)
|
||||||
}}"
|
}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
val joinToString = map.joinToString("\n")
|
val joinToString = map.joinToString("\n")
|
||||||
//language=kotlin
|
//language=kotlin
|
||||||
val trimIndent =
|
val trimIndent =
|
||||||
"""@Suppress("unused")
|
"""@Suppress("unused")
|
||||||
interface UnicodeEmoji {
|
interface UnicodeEmoji {
|
||||||
val group: String
|
val group: String
|
||||||
val subgroup: String
|
val subgroup: String
|
||||||
|
@ -185,9 +182,9 @@ init {
|
||||||
}
|
}
|
||||||
${joinToString}
|
${joinToString}
|
||||||
}"""
|
}"""
|
||||||
asFile.writeText(trimIndent)
|
asFile.writeText(trimIndent)
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue