- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
40 lines
1.2 KiB
Swift
40 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
public struct RDEPUBCFIPath: Codable, Equatable, Hashable {
|
|
|
|
public var steps: [RDEPUBCFIStep]
|
|
|
|
public init(steps: [RDEPUBCFIStep] = []) {
|
|
self.steps = steps
|
|
}
|
|
|
|
public func commonPrefix(with other: RDEPUBCFIPath) -> RDEPUBCFIPath {
|
|
var prefix: [RDEPUBCFIStep] = []
|
|
let upperBound = min(steps.count, other.steps.count)
|
|
for index in 0..<upperBound {
|
|
guard steps[index] == other.steps[index] else { break }
|
|
prefix.append(steps[index])
|
|
}
|
|
return RDEPUBCFIPath(steps: prefix)
|
|
}
|
|
|
|
public func droppingPrefix(_ prefix: RDEPUBCFIPath) -> RDEPUBCFIPath {
|
|
guard prefix.steps.count <= steps.count else { return self }
|
|
let candidate = Array(steps.prefix(prefix.steps.count))
|
|
guard candidate == prefix.steps else { return self }
|
|
return RDEPUBCFIPath(steps: Array(steps.dropFirst(prefix.steps.count)))
|
|
}
|
|
}
|
|
|
|
public struct RDEPUBCFIStep: Codable, Equatable, Hashable {
|
|
|
|
public var index: Int
|
|
|
|
public var idAssertion: String?
|
|
|
|
public init(index: Int, idAssertion: String? = nil) {
|
|
self.index = index
|
|
self.idAssertion = idAssertion?.rd_cfiNilIfEmpty
|
|
}
|
|
}
|