-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
95 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.legado.app.utils | ||
|
||
import com.github.liuyueyi.quick.transfer.ChineseUtils | ||
import com.github.liuyueyi.quick.transfer.constants.TransType | ||
import com.github.liuyueyi.quick.transfer.dictionary.DictionaryContainer | ||
|
||
object ChineseUtils { | ||
|
||
private var fixed = false | ||
|
||
fun s2t(content: String): String { | ||
return ChineseUtils.s2t(content) | ||
} | ||
|
||
fun t2s(content: String): String { | ||
if (!fixed) { | ||
fixed = true | ||
fixT2sDict() | ||
} | ||
return ChineseUtils.t2s(content) | ||
} | ||
|
||
fun preLoad(async: Boolean, vararg transType: TransType) { | ||
ChineseUtils.preLoad(async, *transType) | ||
} | ||
|
||
fun unLoad(vararg transType: TransType) { | ||
ChineseUtils.unLoad(*transType) | ||
} | ||
|
||
fun fixT2sDict() { | ||
val dict = DictionaryContainer.getInstance().getDictionary(TransType.TRADITIONAL_TO_SIMPLE) | ||
dict.chars.run { | ||
remove('劈') | ||
remove('脊') | ||
} | ||
kotlin.runCatching { | ||
dict.dict.run { | ||
remove("支援") | ||
remove("路易斯") | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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) { | ||
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 | ||
} | ||
} | ||
} | ||
} |