This commit is contained in:
Horis 2023-12-11 16:16:41 +08:00
parent e86c211b58
commit 635d4360d9
2 changed files with 30 additions and 22 deletions

View File

@ -2,6 +2,7 @@ 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 import com.github.liuyueyi.quick.transfer.dictionary.DictionaryContainer
object ChineseUtils { object ChineseUtils {
@ -30,15 +31,20 @@ object ChineseUtils {
fun fixT2sDict() { fun fixT2sDict() {
val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE) val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE)
dict.chars.run { dict.run {
remove('劈') remove("")
remove('脊') remove("")
remove("支援")
remove("沈默")
remove("路易斯")
} }
kotlin.runCatching { }
dict.dict.run {
remove("支援") fun BasicDictionary.remove(key: String) {
remove("路易斯") if (key.length == 1) {
} chars.remove(key[0])
} else {
dict.remove(key)
} }
} }

View File

@ -19,20 +19,22 @@ fun <T> TrieNode<T>.getChildren(): HashMap<Char, TrieNode<T>> {
} }
fun <T> Trie<T>.remove(value: String) { fun <T> Trie<T>.remove(value: String) {
var node = getRoot() kotlin.runCatching {
val nodes = arrayListOf<TrieNode<T>>() var node = getRoot()
val chars = value.toCharArray() val nodes = arrayListOf<TrieNode<T>>()
for (c in chars) { val chars = value.toCharArray()
nodes.add(node) for (c in chars) {
node = node.getChildren()[c] ?: break nodes.add(node)
if (!node.isLeaf) { node = node.getChildren()[c] ?: break
continue if (!node.isLeaf) {
} continue
for ((ch, n) in chars.reversed().zip(nodes.reversed())) { }
val children = n.getChildren() for ((ch, n) in chars.reversed().zip(nodes.reversed())) {
children.remove(ch) val children = n.getChildren()
if (children.isNotEmpty()) { children.remove(ch)
break if (children.isNotEmpty()) {
break
}
} }
} }
} }