LMAssembly // Format tweaks.

This commit is contained in:
ShikiSuen 2022-10-14 22:21:00 +08:00
parent 04bdb0db47
commit fd3c48bf02
5 changed files with 20 additions and 60 deletions

View File

@ -16,17 +16,13 @@ extension vChewingLM {
var rangeMap: [String: [(Range<String.Index>, Int)]] = [:]
var strData: String = ""
public var count: Int {
rangeMap.count
}
public var count: Int { rangeMap.count }
public init() {
rangeMap = [:]
}
public var isLoaded: Bool {
!rangeMap.isEmpty
}
public var isLoaded: Bool { !rangeMap.isEmpty }
internal func cnvNGramKeyFromPinyinToPhona(target: String) -> String {
guard target.contains("("), target.contains(","), target.contains(")") else {
@ -40,9 +36,7 @@ extension vChewingLM {
}
@discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded {
return false
}
if isLoaded { return false }
LMConsolidator.fixEOF(path: path)
LMConsolidator.consolidate(path: path, pragma: true)
@ -72,10 +66,8 @@ extension vChewingLM {
}
public mutating func close() {
if isLoaded {
rangeMap.removeAll()
}
}
public func valuesFor(pair: Megrez.Compositor.KeyValuePaired) -> [String] {
var pairs: [String] = []

View File

@ -30,9 +30,7 @@ extension vChewingLM {
var shouldForceDefaultScore = false
///
public var count: Int {
rangeMap.count
}
public var count: Int { rangeMap.count }
///
///
@ -53,17 +51,13 @@ extension vChewingLM {
}
///
public var isLoaded: Bool {
!rangeMap.isEmpty
}
public var isLoaded: Bool { !rangeMap.isEmpty }
///
/// - parameters:
/// - path:
@discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded {
return false
}
if isLoaded { return false }
if allowConsolidation {
LMConsolidator.fixEOF(path: path)
@ -95,10 +89,8 @@ extension vChewingLM {
///
public mutating func close() {
if isLoaded {
rangeMap.removeAll()
}
}
// MARK: - Advanced features

View File

@ -29,9 +29,7 @@ extension vChewingLM {
var shouldForceDefaultScore = false
///
public var count: Int {
rangeMap.count
}
public var count: Int { rangeMap.count }
///
///
@ -54,17 +52,13 @@ extension vChewingLM {
}
///
public var isLoaded: Bool {
!rangeMap.isEmpty
}
public var isLoaded: Bool { !rangeMap.isEmpty }
///
/// - parameters:
/// - path:
@discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded {
return false
}
if isLoaded { return false }
do {
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
@ -81,10 +75,8 @@ extension vChewingLM {
///
public mutating func close() {
if isLoaded {
rangeMap.removeAll()
}
}
// MARK: - Advanced features

View File

@ -14,22 +14,16 @@ extension vChewingLM {
@frozen public struct LMPlainBopomofo {
var rangeMap: [String: String] = [:]
public var count: Int {
rangeMap.count
}
public var count: Int { rangeMap.count }
public init() {
rangeMap = [:]
}
public var isLoaded: Bool {
!rangeMap.isEmpty
}
public var isLoaded: Bool { !rangeMap.isEmpty }
@discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded {
return false
}
if isLoaded { return false }
do {
let rawData = try Data(contentsOf: URL(fileURLWithPath: path))
@ -46,10 +40,8 @@ extension vChewingLM {
}
public mutating func close() {
if isLoaded {
rangeMap.removeAll()
}
}
public func valuesFor(key: String) -> [String] {
var pairs: [String] = []

View File

@ -14,22 +14,16 @@ extension vChewingLM {
var rangeMap: [String: Range<String.Index>] = [:]
var strData: String = ""
public var count: Int {
rangeMap.count
}
public var count: Int { rangeMap.count }
public init() {
rangeMap = [:]
}
public var isLoaded: Bool {
!rangeMap.isEmpty
}
public var isLoaded: Bool { !rangeMap.isEmpty }
@discardableResult public mutating func open(_ path: String) -> Bool {
if isLoaded {
return false
}
if isLoaded { return false }
LMConsolidator.fixEOF(path: path)
LMConsolidator.consolidate(path: path, pragma: true)
@ -57,10 +51,8 @@ extension vChewingLM {
}
public mutating func close() {
if isLoaded {
rangeMap.removeAll()
}
}
public func dump() {
var strDump = ""