Horis 2 лет назад
Родитель
Сommit
1ac3ebb358

+ 14 - 8
app/src/main/java/io/legado/app/utils/ChineseUtils.kt

@@ -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 {
-            remove('劈')
-            remove('脊')
+        dict.run {
+            remove("劈")
+            remove("脊")
+            remove("支援")
+            remove("沈默")
+            remove("路易斯")
         }
         }
-        kotlin.runCatching {
-            dict.dict.run {
-                remove("支援")
-                remove("路易斯")
-            }
+    }
+
+    fun BasicDictionary.remove(key: String) {
+        if (key.length == 1) {
+            chars.remove(key[0])
+        } else {
+            dict.remove(key)
         }
         }
     }
     }
 
 

+ 16 - 14
app/src/main/java/io/legado/app/utils/TrieExtensions.kt

@@ -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()
-    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
+    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
+                }
             }
             }
         }
         }
     }
     }