LMMgr & PhraseEditorDelegate // Add tagOverrides(), etc.
This commit is contained in:
parent
34e9ca9493
commit
59903995ce
|
@ -18,4 +18,5 @@ public protocol PhraseEditorDelegate {
|
||||||
func checkIfUserPhraseExist(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool
|
func checkIfUserPhraseExist(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool
|
||||||
func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool)
|
func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool)
|
||||||
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String)
|
func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String)
|
||||||
|
func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,11 +276,18 @@ public class LMMgr {
|
||||||
public static func checkIfUserPhraseExist(
|
public static func checkIfUserPhraseExist(
|
||||||
userPhrase: String,
|
userPhrase: String,
|
||||||
mode: Shared.InputMode,
|
mode: Shared.InputMode,
|
||||||
key unigramKey: String
|
key unigramKey: String,
|
||||||
|
factoryDictionaryOnly: Bool = false
|
||||||
) -> Bool {
|
) -> Bool {
|
||||||
switch mode {
|
switch mode {
|
||||||
case .imeModeCHS: return lmCHS.hasKeyValuePairFor(keyArray: [unigramKey], value: userPhrase)
|
case .imeModeCHS:
|
||||||
case .imeModeCHT: return lmCHT.hasKeyValuePairFor(keyArray: [unigramKey], value: userPhrase)
|
return lmCHS.hasKeyValuePairFor(
|
||||||
|
keyArray: [unigramKey], value: userPhrase, factoryDictionaryOnly: factoryDictionaryOnly
|
||||||
|
)
|
||||||
|
case .imeModeCHT:
|
||||||
|
return lmCHT.hasKeyValuePairFor(
|
||||||
|
keyArray: [unigramKey], value: userPhrase, factoryDictionaryOnly: factoryDictionaryOnly
|
||||||
|
)
|
||||||
case .imeModeNULL: return false
|
case .imeModeNULL: return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -782,4 +789,20 @@ extension LMMgr: PhraseEditorDelegate {
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode) {
|
||||||
|
let outputStack: NSMutableString = .init()
|
||||||
|
for currentLine in strProcessed.split(separator: "\n") {
|
||||||
|
let arr = currentLine.split(separator: " ")
|
||||||
|
guard arr.count >= 2 else { continue }
|
||||||
|
let exists = Self.checkIfUserPhraseExist(
|
||||||
|
userPhrase: arr[0].description, mode: mode, key: arr[1].description, factoryDictionaryOnly: true
|
||||||
|
)
|
||||||
|
outputStack.append(currentLine.description)
|
||||||
|
let replace = !currentLine.contains(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎") && exists
|
||||||
|
if replace { outputStack.append(" #𝙾𝚟𝚎𝚛𝚛𝚒𝚍𝚎") }
|
||||||
|
outputStack.append("\n")
|
||||||
|
}
|
||||||
|
strProcessed = outputStack.description
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue