Skip to content

Commit 9e7b773

Browse files
committed
[Bootstrap] Simplify codepoints parsing
1 parent b066299 commit 9e7b773

2 files changed

Lines changed: 2 additions & 14 deletions

File tree

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/bootstrap/data/BootstrapRepository.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import kotlinx.coroutines.sync.Mutex
1111
import kotlinx.coroutines.sync.withLock
1212
import kotlinx.coroutines.withContext
1313
import kotlinx.serialization.json.Json
14-
import kotlinx.serialization.json.jsonObject
15-
import kotlinx.serialization.json.jsonPrimitive
1614

1715
class BootstrapRepository(
1816
private val httpClient: HttpClient,
@@ -30,8 +28,6 @@ class BootstrapRepository(
3028
private var fontBytesCache: ByteArray? = null
3129
private var codepointsCache: Map<String, Int>? = null
3230

33-
suspend fun loadIconList(): Map<String, Int> = loadCodepoints()
34-
3531
suspend fun loadFontBytes(): ByteArray = withContext(Dispatchers.IO) {
3632
fontMutex.withLock {
3733
fontBytesCache ?: run {
@@ -48,7 +44,7 @@ class BootstrapRepository(
4844
codepointMutex.withLock {
4945
codepointsCache ?: run {
5046
val jsonText = httpClient.get(JSON_URL).bodyAsText()
51-
val codepoints = parseCodepoints(jsonText)
47+
val codepoints = json.decodeFromString<Map<String, Int>>(jsonText)
5248
codepointsCache = codepoints
5349
codepoints
5450
}
@@ -58,12 +54,4 @@ class BootstrapRepository(
5854
suspend fun downloadSvg(iconName: String): String = withContext(Dispatchers.IO) {
5955
httpClient.get("$ICONS_BASE_URL/$iconName.svg").bodyAsText()
6056
}
61-
62-
private fun parseCodepoints(jsonText: String): Map<String, Int> {
63-
val jsonObject = json.parseToJsonElement(jsonText).jsonObject
64-
return jsonObject.entries.mapNotNull { (name, value) ->
65-
val codepoint = value.jsonPrimitive.content.toIntOrNull() ?: return@mapNotNull null
66-
name to codepoint
67-
}.toMap()
68-
}
6957
}

tools/idea-plugin/src/main/kotlin/io/github/composegears/valkyrie/ui/screen/webimport/standard/bootstrap/domain/BootstrapUseCase.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class BootstrapUseCase(
2929
}
3030

3131
override suspend fun loadConfig(): StandardIconConfig {
32-
val codepoints = repository.loadIconList()
32+
val codepoints = repository.loadCodepoints()
3333

3434
val icons: List<StandardIcon> = codepoints.map { (name, codepoint) ->
3535
StandardIcon(

0 commit comments

Comments
 (0)