fix: 正常に絵文字が出力されない問題を修正

This commit is contained in:
usbharu 2024-09-08 18:15:43 +09:00
parent 434560ecd4
commit 7d1063b0c3
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
1 changed files with 83 additions and 64 deletions

View File

@ -2,10 +2,16 @@ import io.ktor.client.*
import io.ktor.client.engine.cio.* import io.ktor.client.engine.cio.*
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.statement.* import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.gradle.api.Action import org.gradle.api.Action
import org.gradle.api.Plugin import org.gradle.api.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import java.net.URI
import java.net.http.HttpClient
import java.net.http.HttpRequest
import java.net.http.HttpResponse
import java.time.Duration
class EmojiPlugin : Plugin<Project> { class EmojiPlugin : Plugin<Project> {
override fun apply(project: Project) { override fun apply(project: Project) {
@ -13,10 +19,25 @@ class EmojiPlugin : Plugin<Project> {
.doLast(Action { .doLast(Action {
runBlocking { runBlocking {
val httpClient = HttpClient(CIO)
val bodyAsText = val httpClient = HttpClient.newBuilder()
httpClient.get("https://unicode.org/Public/emoji/15.0/emoji-test.txt") .version(HttpClient.Version.HTTP_1_1)
.bodyAsText() .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 bodyAsText = httpClient.send(req, HttpResponse.BodyHandlers.ofString()).body()
println(project.buildDir.path) println(project.buildDir.path)
// println(bodyAsText) // println(bodyAsText)
@ -39,7 +60,7 @@ class EmojiPlugin : Plugin<Project> {
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++
} }
@ -58,13 +79,12 @@ class EmojiPlugin : Plugin<Project> {
else -> { else -> {
val description = s.substringAfterLast("E").substringAfter(" ") val description = s.substringAfterLast("E").substringAfter(" ")
val status = s.substringAfter(";").substringBefore("#").trim() val status = s.substringAfter(";").substringBefore("#").trim()
if (true) {
val code = val code =
s.substringBefore(";").replace(Regex(" +"), " ").trim() s.substringBefore(";").replace(Regex(" +"), " ").trim()
val char = s.substringAfter("# ").substringBefore(" ").trim() val char = s.substringAfter("# ").substringBefore(" ").trim()
val statusString = when(status){ val statusString = when (status) {
"fully-qualified" -> "Status.FULLY_QUALIFIED" "fully-qualified" -> "Status.FULLY_QUALIFIED"
"unqualified" -> "Status.UNAUALIFIED" "unqualified" -> "Status.UNAUALIFIED"
"minimally-qualified" -> "Status.MINIMALLY_QUALIFIED" "minimally-qualified" -> "Status.MINIMALLY_QUALIFIED"
@ -75,10 +95,10 @@ class EmojiPlugin : Plugin<Project> {
} }
} }
enumList.put( enumList.putIfAbsent(
description, description,
Emoji( Emoji(
group+groupCount, group + groupCount,
"${ "${
(description + "_" + status).toUpperCase() (description + "_" + status).toUpperCase()
.replace(" ", "_") .replace(" ", "_")
@ -124,7 +144,6 @@ class EmojiPlugin : Plugin<Project> {
} }
} }
} }
}
val emojis = mutableMapOf<String, MutableList<Emoji>>() val emojis = mutableMapOf<String, MutableList<Emoji>>()
enumList.values.forEach { enumList.values.forEach {
emojis.getOrPut( emojis.getOrPut(