Skip to content

Commit 1375a98

Browse files
refactor:
* update new version
1 parent 478e684 commit 1375a98

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

build.gradle.kts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
33
plugins {
44
id("maven-publish")
55
kotlin("jvm") version "1.6.21"
6-
application
76
}
87

98
group = "net.purefunc"
@@ -36,8 +35,4 @@ publishing {
3635
from(components["java"])
3736
}
3837
}
39-
}
40-
41-
application {
42-
mainClass.set("net.purefunc.generate.MainKt")
4338
}

src/main/kotlin/net/purefunc/generate/Main.kt

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,35 @@ import java.io.FileOutputStream
55
import java.util.Locale
66

77
fun main() {
8+
// collect emoji lines
89
val lines = mutableListOf<String>()
910
var flag = false
1011
File("emoji-test.txt").forEachLine { line ->
1112
if (line == "") flag = false
1213
if (flag) lines.add(line)
1314
if (line.startsWith("# subgroup: ")) flag = true
1415
}
15-
val resulta = lines.filter { it.contains("fully-qualified") }.map { it.split(" ") }.map {
16+
17+
val bigEnum = lines.filter {
18+
it.contains("fully-qualified")
19+
}.map {
20+
it.split(" ")
21+
}.map {
1622
val items = mutableListOf<String>()
17-
items.add(it[0])
23+
24+
// find code part
25+
var codeIdx = 0
26+
it.forEachIndexed { index, element -> if (element == "") codeIdx = index }
27+
(0 until codeIdx).forEach { i ->
28+
items.add(it[i])
29+
}
30+
31+
// find index start from E
1832
var idx = 0
1933
it.forEachIndexed { index, element -> if (element.startsWith("E") && element.contains(".")) idx = index }
34+
2035
items.addAll(
36+
// process item name
2137
it.subList(idx + 1, it.size).map { str ->
2238
str.replace("", "")
2339
.replace("", "")
@@ -38,34 +54,34 @@ fun main() {
3854
.replace("&", "and")
3955
}
4056
)
57+
4158
items
4259
}
4360

44-
val size = (resulta.size / 1000)
45-
46-
val resultList = (0..size).map {
47-
if (resulta.size < 1000 * (it + 1)) {
48-
resulta.subList(1000 * it, resulta.size)
61+
val pageCount = 1000
62+
val pageSize = (bigEnum.size / pageCount)
63+
val pagingItems = (0..pageSize).map { page ->
64+
if (pageCount * (page + 1) > bigEnum.size) {
65+
bigEnum.subList(pageCount * page, bigEnum.size)
4966
} else {
50-
51-
resulta.subList(1000 * it, 1000 * (it + 1))
67+
bigEnum.subList(pageCount * page, pageCount * (page + 1))
5268
}
5369
}
5470

55-
resultList.forEachIndexed { idx, result ->
56-
val fos = FileOutputStream(File("src/main/kotlin/net/purefunc/emoji/Emoji$idx.kt"))
71+
pagingItems.forEachIndexed { fileIdx, item ->
72+
val fos = FileOutputStream(File("src/main/kotlin/net/purefunc/emoji/Emoji$fileIdx.kt"))
5773
fos.write("package net.purefunc.emoji\n".toByteArray())
5874
fos.write("\n".toByteArray())
59-
fos.write("enum class Emoji$idx(\n".toByteArray())
60-
fos.write(" private val code: Int,\n".toByteArray())
75+
fos.write("enum class Emoji$fileIdx(\n".toByteArray())
76+
fos.write(" private val intArray: IntArray,\n".toByteArray())
6177
fos.write(") {\n".toByteArray())
6278
fos.write("\n".toByteArray())
6379

64-
result.forEachIndexed { index, strings ->
80+
item.forEachIndexed { idx, strings ->
6581
val s = " ${
6682
strings.subList(1, strings.size).joinToString("_") { it.uppercase(Locale.getDefault()) }
67-
}(0x${strings[0]})"
68-
if (index == result.size - 1) {
83+
}(intArrayOf(0x${strings[0]}))"
84+
if (idx == item.size - 1) {
6985
fos.write("$s;\n".toByteArray())
7086
} else {
7187
fos.write("$s,\n".toByteArray())

src/test/kotlin/net/purefunc/emoji/EmojiTests.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ class EmojiTests {
66

77
@Test
88
internal fun `println emoji`() {
9+
val ints = arrayOf(0x263A, 0xFE0F).toIntArray()
10+
println(String(ints, 0, ints.size))
11+
912
Emoji0.values().forEach {
1013
println(it)
1114
}

0 commit comments

Comments
 (0)