Repo // Using map(\.description) in lieu of charComponents().
This commit is contained in:
parent
7beb6d3cd2
commit
18bdf80afd
|
@ -27,16 +27,6 @@ fileprivate extension String {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - String charComponents Extension
|
||||
|
||||
public extension String {
|
||||
var charComponents: [String] { map { String($0) } }
|
||||
}
|
||||
|
||||
public extension Array where Element == String.Element {
|
||||
var charComponents: [String] { map { String($0) } }
|
||||
}
|
||||
|
||||
// MARK: - StringView Ranges Extension (by Isaac Xen)
|
||||
|
||||
fileprivate extension String {
|
||||
|
@ -717,7 +707,7 @@ func healthCheck(_ data: [Unigram]) -> String {
|
|||
break outerMatchCheck
|
||||
}
|
||||
innerMatchCheck: if checkPerCharMachingStatus {
|
||||
let char = neta.value.charComponents[i]
|
||||
let char = neta.value.map(\.description)[i]
|
||||
if exceptedChars.contains(char) { break innerMatchCheck }
|
||||
guard let queriedPhones = mapReverseLookupForCheck[char] else {
|
||||
bad = true
|
||||
|
|
|
@ -315,7 +315,7 @@ extension CandidatePool {
|
|||
}
|
||||
} else {
|
||||
for (i, neta) in candidateRow.enumerated() {
|
||||
neta.key = selectionKeys.map { String($0) }[i]
|
||||
neta.key = selectionKeys.map(\.description)[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ extension CandidatePool {
|
|||
} else {
|
||||
for (i, neta) in candidateColumn.enumerated() {
|
||||
if neta.key.isEmpty { continue }
|
||||
neta.key = selectionKeys.map { String($0) }[i]
|
||||
neta.key = selectionKeys.map(\.description)[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,7 +329,7 @@ public extension vChewingLM {
|
|||
// 將兩句差分也是為了讓 rawUserUnigrams 的類型不受可能的影響。
|
||||
rawAllUnigrams += lmUserPhrases.unigramsFor(key: keyChain).reversed()
|
||||
|
||||
if !isCassetteEnabled || isCassetteEnabled && keyChain.charComponents[0] == "_" {
|
||||
if !isCassetteEnabled || isCassetteEnabled && keyChain.map(\.description)[0] == "_" {
|
||||
// LMMisc 與 LMCore 的 score 在 (-10.0, 0.0) 這個區間內。
|
||||
rawAllUnigrams += lmMisc.unigramsFor(key: keyChain)
|
||||
rawAllUnigrams += lmCore.unigramsFor(key: keyChain)
|
||||
|
|
|
@ -107,7 +107,7 @@ public extension vChewingLM {
|
|||
theMaxKeyLength = max(theMaxKeyLength, cells[0].count)
|
||||
charDefMap[strFirstCell, default: []].append(strSecondCell)
|
||||
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
|
||||
var keyComps = strFirstCell.charComponents
|
||||
var keyComps = strFirstCell.map(\.description)
|
||||
while !keyComps.isEmpty {
|
||||
keyComps.removeLast()
|
||||
charDefWildcardMap[keyComps.joined() + wildcard, default: []].append(strSecondCell)
|
||||
|
@ -138,10 +138,10 @@ public extension vChewingLM {
|
|||
if nameCJK.isEmpty, strLine.contains("%cname ") { nameCJK = strSecondCell }
|
||||
if nameShort.isEmpty, strLine.contains("%sname ") { nameShort = strSecondCell }
|
||||
if selectionKeys.isEmpty, strLine.contains("%selkey ") {
|
||||
selectionKeys = cells[1].map { String($0) }.deduplicated
|
||||
selectionKeys = cells[1].map(\.description).deduplicated
|
||||
}
|
||||
if endKeys.isEmpty, strLine.contains("%endkey ") {
|
||||
endKeys = cells[1].map { String($0) }.deduplicated
|
||||
endKeys = cells[1].map(\.description).deduplicated
|
||||
}
|
||||
if wildcardKey.isEmpty, strLine.contains("%wildcardkey ") {
|
||||
wildcardKey = cells[1].first?.description ?? ""
|
||||
|
|
|
@ -61,7 +61,7 @@ public extension vChewingLM {
|
|||
public func valuesFor(key: String) -> [String] {
|
||||
var pairs: [String] = []
|
||||
if let arrRangeRecords: String = dataMap[key]?.trimmingCharacters(in: .newlines) {
|
||||
pairs.append(contentsOf: arrRangeRecords.map { String($0) })
|
||||
pairs.append(contentsOf: arrRangeRecords.map(\.description))
|
||||
}
|
||||
return pairs.deduplicated
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ extension Megrez.Compositor {
|
|||
func getJoinedKeyArray(range: Range<Int>) -> [String] {
|
||||
// 下面這句不能用 contains,不然會要求至少 macOS 13 Ventura。
|
||||
guard range.upperBound <= keys.count, range.lowerBound >= 0 else { return [] }
|
||||
return keys[range].map { String($0) }
|
||||
return keys[range].map(\.description)
|
||||
}
|
||||
|
||||
/// 在指定位置(以指定索引鍵陣列和指定幅位長度)拿取節點。
|
||||
|
|
|
@ -25,16 +25,6 @@ public extension RangeReplaceableCollection where Element: Hashable {
|
|||
}
|
||||
}
|
||||
|
||||
// MARK: - String charComponents Extension
|
||||
|
||||
public extension String {
|
||||
var charComponents: [String] { map { String($0) } }
|
||||
}
|
||||
|
||||
public extension Array where Element == String.Element {
|
||||
var charComponents: [String] { map { String($0) } }
|
||||
}
|
||||
|
||||
// MARK: - String Tildes Expansion Extension
|
||||
|
||||
public extension String {
|
||||
|
|
|
@ -32,10 +32,10 @@ public enum ChineseConverter {
|
|||
// 給 JIS 轉換模式新增疊字符號支援。
|
||||
private static func processKanjiRepeatSymbol(target: inout String) {
|
||||
guard !target.isEmpty else { return }
|
||||
var arr = target.charComponents
|
||||
var arr = target.map(\.description)
|
||||
for (i, char) in arr.enumerated() {
|
||||
if i == 0 { continue }
|
||||
if char == target.charComponents[i - 1] {
|
||||
if char == target.map(\.description)[i - 1] {
|
||||
arr[i] = "々"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,11 +62,11 @@ public struct IMEStateData: IMEStateDataProtocol {
|
|||
/// 所以在這裡必須做糾偏處理。因為在用 Swift,所以可以用「.utf16」取代「NSString.length()」。
|
||||
/// 這樣就可以免除不必要的類型轉換。
|
||||
public var u16Cursor: Int {
|
||||
displayedText.charComponents[0 ..< cursor].joined().utf16.count
|
||||
displayedText.map(\.description)[0 ..< cursor].joined().utf16.count
|
||||
}
|
||||
|
||||
public var u16Marker: Int {
|
||||
displayedText.charComponents[0 ..< marker].joined().utf16.count
|
||||
displayedText.map(\.description)[0 ..< marker].joined().utf16.count
|
||||
}
|
||||
|
||||
public var u16MarkedRange: Range<Int> {
|
||||
|
@ -170,7 +170,7 @@ public struct IMEStateData: IMEStateDataProtocol {
|
|||
|
||||
public extension IMEStateData {
|
||||
var doesUserPhraseExist: Bool {
|
||||
let text = displayedText.charComponents[markedRange].joined()
|
||||
let text = displayedText.map(\.description)[markedRange].joined()
|
||||
let joined = markedReadings.joined(separator: InputHandler.keySeparator)
|
||||
return LMMgr.checkIfUserPhraseExist(
|
||||
userPhrase: text, mode: IMEApp.currentInputMode, key: joined
|
||||
|
@ -207,7 +207,7 @@ public extension IMEStateData {
|
|||
|
||||
var userPhraseKVPair: (String, String) {
|
||||
let key = markedReadings.joined(separator: InputHandler.keySeparator)
|
||||
let value = displayedText.charComponents[markedRange].joined()
|
||||
let value = displayedText.map(\.description)[markedRange].joined()
|
||||
return (key, value)
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ public class InputHandler: InputHandlerProtocol {
|
|||
position += currentNode.keyArray.count
|
||||
continue
|
||||
}
|
||||
let values = currentNode.currentPair.value.charComponents
|
||||
let values = currentNode.currentPair.value.map(\.description)
|
||||
for (subPosition, key) in currentNode.keyArray.enumerated() {
|
||||
guard values.count > subPosition else { break } // 防呆,應該沒有發生的可能性
|
||||
let thePair = Megrez.Compositor.KeyValuePaired(
|
||||
|
@ -447,7 +447,7 @@ public class InputHandler: InputHandlerProtocol {
|
|||
if compositor.cursor == 0 { return nil }
|
||||
let cursorPrevious = max(compositor.cursor - 1, 0)
|
||||
let rawData = compositor.keys[cursorPrevious]
|
||||
let components = rawData.charComponents
|
||||
let components = rawData.map(\.description)
|
||||
var hasIntonation = false
|
||||
for neta in components {
|
||||
if !Tekkon.allowedPhonabets.contains(neta) || neta == " " { return nil }
|
||||
|
@ -473,7 +473,7 @@ public class InputHandler: InputHandlerProtocol {
|
|||
return composer.getInlineCompositionForDisplay(isHanyuPinyin: prefs.showHanyuPinyinInCompositionBuffer)
|
||||
}
|
||||
if !prefs.showTranslatedStrokesInCompositionBuffer { return calligrapher }
|
||||
return calligrapher.charComponents.map {
|
||||
return calligrapher.map(\.description).map {
|
||||
currentLM.convertCassetteKeyToDisplay(char: $0)
|
||||
}.joined()
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ extension InputHandler {
|
|||
textToCommit += node.currentPair.value
|
||||
} else {
|
||||
delta = min(delta, node.keyArray.count)
|
||||
textToCommit += node.currentPair.value.charComponents[0 ..< delta].joined()
|
||||
textToCommit += node.currentPair.value.map(\.description)[0 ..< delta].joined()
|
||||
}
|
||||
let newCursor = max(compositor.cursor - delta, 0)
|
||||
compositor.cursor = 0
|
||||
|
|
|
@ -133,7 +133,7 @@ extension InputHandler {
|
|||
let selectionKeys = delegate.selectionKeys
|
||||
|
||||
for j in 0 ..< selectionKeys.count {
|
||||
let label = selectionKeys.charComponents[j]
|
||||
let label = selectionKeys.map(\.description)[j]
|
||||
if match.compare(label, options: .caseInsensitive, range: nil, locale: .current) == .orderedSame {
|
||||
index = j
|
||||
break
|
||||
|
|
|
@ -47,7 +47,7 @@ extension InputHandler {
|
|||
// prevReading 的內容分別是:「完整讀音」「去掉聲調的讀音」「是否有聲調」。
|
||||
guard let prevReading = previousParsableReading, isIntonationKey(input) else { break proc }
|
||||
var theComposer = composer
|
||||
prevReading.0.charComponents.forEach { theComposer.receiveKey(fromPhonabet: $0) }
|
||||
prevReading.0.map(\.description).forEach { theComposer.receiveKey(fromPhonabet: $0) }
|
||||
// 發現要覆寫的聲調與覆寫對象的聲調雷同的情況的話,直接跳過處理。
|
||||
let oldIntonation: Tekkon.Phonabet = theComposer.intonation
|
||||
theComposer.receiveKey(fromString: input.text)
|
||||
|
|
|
@ -300,7 +300,7 @@ extension InputHandler {
|
|||
var displayedText = state.displayedText
|
||||
|
||||
if input.modifierFlags == [.option, .shift] {
|
||||
displayedText = displayedText.charComponents.joined(separator: " ")
|
||||
displayedText = displayedText.map(\.description).joined(separator: " ")
|
||||
} else if readingOnly {
|
||||
displayedText = commissionByCtrlCommandEnter()
|
||||
} else if input.isCommandHold, input.isControlHold {
|
||||
|
@ -426,7 +426,7 @@ extension InputHandler {
|
|||
// prevReading 的內容分別是:「完整讀音」「去掉聲調的讀音」「是否有聲調」。
|
||||
compositor.dropKey(direction: .rear)
|
||||
walk() // 這裡必須 Walk 一次、來更新目前被 walk 的內容。
|
||||
prevReading.1.charComponents.forEach { composer.receiveKey(fromPhonabet: $0) }
|
||||
prevReading.1.map(\.description).forEach { composer.receiveKey(fromPhonabet: $0) }
|
||||
}
|
||||
delegate.switchState(generateStateOfInputting())
|
||||
return true
|
||||
|
|
|
@ -22,7 +22,14 @@ extension CandidateNode {
|
|||
switch fieldSlice.count {
|
||||
case 1: arrMembers.append(.init(name: String(fieldSlice[0])))
|
||||
case 2:
|
||||
arrMembers.append(.init(name: String(fieldSlice[0]), symbols: .init(fieldSlice[1].map { String($0) })))
|
||||
arrMembers.append(
|
||||
.init(
|
||||
name: String(fieldSlice[0]),
|
||||
symbols: .init(
|
||||
fieldSlice[1].map(\.description)
|
||||
)
|
||||
)
|
||||
)
|
||||
default: break
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ class FrmRevLookupWindow: NSWindow {
|
|||
strBuilder.append("Char\tReading(s)\n".localized)
|
||||
strBuilder.append("==\t====\n")
|
||||
var i = 0
|
||||
theLoop: for char in input.charComponents {
|
||||
theLoop: for char in input.map(\.description) {
|
||||
if i == 15 {
|
||||
strBuilder.append("Maximum 15 results returnable.".localized + "\n")
|
||||
break theLoop
|
||||
|
|
Loading…
Reference in New Issue