@@ -5,19 +5,35 @@ import java.io.FileOutputStream
55import java.util.Locale
66
77fun 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())
0 commit comments