50 lines
1.2 KiB
Swift
50 lines
1.2 KiB
Swift
enum Path {
|
|
|
|
// MARK: Functions
|
|
|
|
static func archivePath(from path: String) -> String {
|
|
let pathComponents = path.split(separator: .forwardSlash)
|
|
|
|
return pathComponents.count > 1
|
|
? .init(format: .Format.archiveDocC, String(pathComponents[1]))
|
|
: .empty
|
|
}
|
|
|
|
static func archiveName(from path: String) -> String {
|
|
let pathComponents = path.split(separator: .forwardSlash)
|
|
|
|
return pathComponents.count > 1
|
|
? .init(pathComponents[1]).lowercased()
|
|
: .empty
|
|
}
|
|
|
|
static func resourcePath(from path: String) -> String {
|
|
let matches = path.matches(of: /\//)
|
|
|
|
return matches.count > 2
|
|
? .init(path[matches[2].startIndex...])
|
|
: .forwardSlash
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - String+Constants
|
|
|
|
extension String {
|
|
static let empty = ""
|
|
static let forwardSlash = "/"
|
|
static let previousFolder = ".."
|
|
}
|
|
|
|
// MARK: - Character+Constants
|
|
|
|
private extension Character {
|
|
static let forwardSlash: Character = "/"
|
|
}
|
|
|
|
// MARK: - String+Formats
|
|
|
|
private extension String.Format {
|
|
static let archiveDocC = "/%@.doccarchive"
|
|
}
|