IME candidates separator to use \x1E instead of a comma

This commit is contained in:
minjaesong
2021-11-12 10:11:02 +09:00
parent 23e9dd3114
commit 9ec4ea026d
4 changed files with 18 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ package net.torvald.terrarum.gamecontroller
import net.torvald.terrarum.App.printdbg
import java.io.File
typealias IMECanditates = List<String>
typealias IMECandidates = List<String>
typealias IMEOutput = String
typealias Keysyms = Array<Array<String?>>
@@ -22,8 +22,8 @@ data class TerrarumIME(
val name: String,
val config: TerrarumIMEConf,
// (headkey, shiftin, altgrin, lowLayerKeysym)
val acceptChar: (Int, Boolean, Boolean, String) -> Pair<IMECanditates, IMEOutput>,
val backspace: () -> IMECanditates,
val acceptChar: (Int, Boolean, Boolean, String) -> Pair<IMECandidates, IMEOutput>,
val backspace: () -> IMECandidates,
val endCompose: () -> IMEOutput,
val reset: () -> Unit,
val composing: () -> Boolean

View File

@@ -19,6 +19,10 @@ class IMEProviderDelegate(val ime: IME) {
class IMEDictionary(private val filename: String) {
companion object {
const val CAND_DELIM = '\u001E'
}
private val candidates = HashMap<String, String>(16384)
private val keys = SortedArrayList<String>(16384) // keys on the .han file are absofreakinlutely not sorted
@@ -30,7 +34,7 @@ class IMEDictionary(private val filename: String) {
if (it.contains(',')) {
val (key, value) = it.split(',')
if (candidates.containsKey(key)) {
candidates[key] += ",$value"
candidates[key] += "$CAND_DELIM$value"
}
else {
candidates[key] = value
@@ -80,8 +84,8 @@ class IMEDictionary(private val filename: String) {
val keysym = allRelevantKeys[index]
if (!keysym.startsWith(key)) break
val outstr = ",${candidates[keysym]}"
outsize += outstr.count { it == ',' }
val outstr = "$CAND_DELIM${candidates[keysym]}"
outsize += outstr.count { it == CAND_DELIM }
out.append(outstr)
index += 1