优化
This commit is contained in:
@@ -2,8 +2,6 @@ package io.legado.app.utils
|
|||||||
|
|
||||||
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
import com.github.liuyueyi.quick.transfer.ChineseUtils
|
||||||
import com.github.liuyueyi.quick.transfer.constants.TransType
|
import com.github.liuyueyi.quick.transfer.constants.TransType
|
||||||
import com.github.liuyueyi.quick.transfer.dictionary.BasicDictionary
|
|
||||||
import com.github.liuyueyi.quick.transfer.dictionary.DictionaryContainer
|
|
||||||
|
|
||||||
object ChineseUtils {
|
object ChineseUtils {
|
||||||
|
|
||||||
@@ -15,7 +13,6 @@ object ChineseUtils {
|
|||||||
|
|
||||||
fun t2s(content: String): String {
|
fun t2s(content: String): String {
|
||||||
if (!fixed) {
|
if (!fixed) {
|
||||||
fixed = true
|
|
||||||
fixT2sDict()
|
fixT2sDict()
|
||||||
}
|
}
|
||||||
return ChineseUtils.t2s(content)
|
return ChineseUtils.t2s(content)
|
||||||
@@ -30,29 +27,18 @@ object ChineseUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun fixT2sDict() {
|
fun fixT2sDict() {
|
||||||
val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE)
|
fixed = true
|
||||||
dict.run {
|
val excludeList = listOf(
|
||||||
remove(
|
"槃",
|
||||||
"劈", "脊", "槃",
|
"划槳", "列根", "雪梨", "雪糕",
|
||||||
"支援", "沈默", "類比", "模擬", "划槳", "列根", "先進", "雪梨", "雪糕",
|
"零錢", "零钱", "離線", "碟片", "模組", "桌球", "案頭", "機車", "電漿",
|
||||||
"零錢", "零钱", "離線", "碟片", "模組", "桌球", "案頭", "機車", "電漿",
|
"鳳梨", "魔戒", "載入", "菲林", "整合", "變數",
|
||||||
"鳳梨", "魔戒", "載入", "菲林", "整合",
|
"路易斯", "非同步", "出租车", "周杰倫", "马铃薯", "馬鈴薯", "機械人", "電單車",
|
||||||
"路易斯", "非同步", "出租车", "周杰倫", "马铃薯", "馬鈴薯", "機械人", "電單車",
|
"電扶梯", "音效卡", "飆車族", "點陣圖", "個入球", "顆進球",
|
||||||
"電扶梯", "音效卡", "飆車族", "點陣圖", "個入球", "顆進球",
|
"魔獸紀元", "高空彈跳", "铁达尼号",
|
||||||
"魔獸紀元", "高空彈跳", "铁达尼号",
|
"魔鬼終結者", "純文字檔案"
|
||||||
"魔鬼終結者", "純文字檔案"
|
)
|
||||||
)
|
ChineseUtils.loadExcludeDict(TransType.TRADITIONAL_TO_SIMPLE, excludeList)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun BasicDictionary.remove(vararg keys: String) {
|
|
||||||
for (key in keys) {
|
|
||||||
if (key.length == 1) {
|
|
||||||
chars.remove(key[0])
|
|
||||||
} else {
|
|
||||||
dict.remove(key)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package io.legado.app.utils
|
|
||||||
|
|
||||||
import com.github.liuyueyi.quick.transfer.Trie
|
|
||||||
import com.github.liuyueyi.quick.transfer.TrieNode
|
|
||||||
import java.util.HashMap
|
|
||||||
|
|
||||||
fun <T> Trie<T>.getRoot(): TrieNode<T> {
|
|
||||||
val rootField = javaClass.getDeclaredField("root")
|
|
||||||
.apply { isAccessible = true }
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return rootField.get(this) as TrieNode<T>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> TrieNode<T>.getChildren(): HashMap<Char, TrieNode<T>> {
|
|
||||||
val childrenField = javaClass.getDeclaredField("children")
|
|
||||||
.apply { isAccessible = true }
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return childrenField.get(this) as HashMap<Char, TrieNode<T>>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T> Trie<T>.remove(value: String) {
|
|
||||||
kotlin.runCatching {
|
|
||||||
var node = getRoot()
|
|
||||||
val nodes = arrayListOf<TrieNode<T>>()
|
|
||||||
val chars = value.toCharArray()
|
|
||||||
for (c in chars) {
|
|
||||||
nodes.add(node)
|
|
||||||
node = node.getChildren()[c] ?: break
|
|
||||||
if (!node.isLeaf) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for ((ch, n) in chars.reversed().zip(nodes.reversed())) {
|
|
||||||
val children = n.getChildren()
|
|
||||||
children.remove(ch)
|
|
||||||
if (children.isNotEmpty()) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -34,7 +34,7 @@ nanoHttpd = "2.3.1"
|
|||||||
okhttp = "4.12.0"
|
okhttp = "4.12.0"
|
||||||
preference = "1.2.1"
|
preference = "1.2.1"
|
||||||
protobufJavalite = "4.26.1"
|
protobufJavalite = "4.26.1"
|
||||||
quickChineseTransfer = "0.2.15"
|
quickChineseTransfer = "0.2.16"
|
||||||
room = "2.6.1"
|
room = "2.6.1"
|
||||||
splitties = "3.0.0"
|
splitties = "3.0.0"
|
||||||
rhino = "1.8.0"
|
rhino = "1.8.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user