LMAssembly // Add replaceData() to certain submodels.
- LMCoreEX // Add replaceData(), etc. - LMReplacements // Add replaceData(), etc. - LMAssociates // Add replaceData(), etc.
This commit is contained in:
parent
2913c22d40
commit
cd85f821d2
|
@ -42,8 +42,23 @@ extension vChewingLM {
|
|||
LMConsolidator.consolidate(path: path, pragma: true)
|
||||
|
||||
do {
|
||||
strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ")
|
||||
strData = strData.replacingOccurrences(of: "\r", with: "\n")
|
||||
let rawStrData = try String(contentsOfFile: path, encoding: .utf8)
|
||||
replaceData(textData: rawStrData)
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/// 將資料從檔案讀入至資料庫辭典內。
|
||||
/// - parameters:
|
||||
/// - path: 給定路徑。
|
||||
public mutating func replaceData(textData rawStrData: String) {
|
||||
if strData == rawStrData { return }
|
||||
strData = rawStrData
|
||||
strData.ranges(splitBy: "\n").filter { !$0.isEmpty }.forEach {
|
||||
let neta = strData[$0].split(separator: " ")
|
||||
if neta.count >= 2 {
|
||||
|
@ -56,13 +71,6 @@ extension vChewingLM {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
public mutating func clear() {
|
||||
|
|
|
@ -60,15 +60,36 @@ extension vChewingLM {
|
|||
/// - path: 給定路徑。
|
||||
@discardableResult public mutating func open(_ path: String) -> Bool {
|
||||
if isLoaded { return false }
|
||||
var consolidated = false
|
||||
|
||||
if allowConsolidation {
|
||||
LMConsolidator.fixEOF(path: path)
|
||||
LMConsolidator.consolidate(path: path, pragma: true)
|
||||
consolidated = true
|
||||
}
|
||||
|
||||
do {
|
||||
strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ")
|
||||
strData = strData.replacingOccurrences(of: "\r", with: "\n")
|
||||
var rawStrData = try String(contentsOfFile: path, encoding: .utf8)
|
||||
if !consolidated {
|
||||
rawStrData = rawStrData.replacingOccurrences(of: "\t", with: " ")
|
||||
rawStrData = rawStrData.replacingOccurrences(of: "\r", with: "\n")
|
||||
}
|
||||
replaceData(textData: rawStrData)
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/// 將資料從檔案讀入至資料庫辭典內。
|
||||
/// - parameters:
|
||||
/// - path: 給定路徑。
|
||||
public mutating func replaceData(textData rawStrData: String) {
|
||||
if strData == rawStrData { return }
|
||||
strData = rawStrData
|
||||
strData.ranges(splitBy: "\n").filter { !$0.isEmpty }.forEach {
|
||||
let neta = strData[$0].split(separator: " ")
|
||||
if neta.count >= 2, String(neta[0]).first != "#" {
|
||||
|
@ -81,13 +102,6 @@ extension vChewingLM {
|
|||
}
|
||||
}
|
||||
temporaryMap.removeAll()
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/// 將當前語言模組的資料庫辭典自記憶體內卸除。
|
||||
|
|
|
@ -29,8 +29,23 @@ extension vChewingLM {
|
|||
LMConsolidator.consolidate(path: path, pragma: true)
|
||||
|
||||
do {
|
||||
strData = try String(contentsOfFile: path, encoding: .utf8).replacingOccurrences(of: "\t", with: " ")
|
||||
strData = strData.replacingOccurrences(of: "\r", with: "\n")
|
||||
let rawStrData = try String(contentsOfFile: path, encoding: .utf8)
|
||||
replaceData(textData: rawStrData)
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
/// 將資料從檔案讀入至資料庫辭典內。
|
||||
/// - parameters:
|
||||
/// - path: 給定路徑。
|
||||
public mutating func replaceData(textData rawStrData: String) {
|
||||
if strData == rawStrData { return }
|
||||
strData = rawStrData
|
||||
strData.ranges(splitBy: "\n").filter { !$0.isEmpty }.forEach {
|
||||
let neta = strData[$0].split(separator: " ")
|
||||
if neta.count >= 2 {
|
||||
|
@ -41,13 +56,6 @@ extension vChewingLM {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
vCLog("\(error)")
|
||||
vCLog("↑ Exception happened when reading data at: \(path).")
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
public mutating func clear() {
|
||||
|
|
Loading…
Reference in New Issue