Added namespaces to some of the constants for the String+Constants extension in the library target.

This commit is contained in:
2025-09-24 18:19:50 +02:00
parent a274547977
commit 9320227c64
5 changed files with 21 additions and 18 deletions
@@ -13,8 +13,18 @@
extension String {
/// An empty string.
static let empty = ""
/// A forwarding slash.
static let forwardSlash = "/"
/// An indication of a previous folder in a path component.
static let previousFolder = ".."
/// A namespace that defines logging representations.
enum Logging {
/// A name of the middleware that triggered a logging event.
static let source = "DocCMiddleware"
}
/// A namespace that defines relative path representations.
enum Path {
/// A forwarding slash.
static let forwardSlash = "/"
/// An indication of a previous folder in a path component.
static let previousFolder = ".."
}
}
@@ -23,8 +23,8 @@ struct CheckURIUseCase {
func callAsFunction(_ uri: URI) -> String? {
guard
let uriPath = uri.path.removingPercentEncoding,
!uriPath.contains(.previousFolder),
uriPath.hasPrefix(.forwardSlash)
!uriPath.contains(.Path.previousFolder),
uriPath.hasPrefix(.Path.forwardSlash)
else {
return nil
}
@@ -56,7 +56,7 @@ struct PrepareURIPathUseCase {
}
let documentationName = uriRest
.split(separator: .forwardSlash)
.split(separator: .Path.forwardSlash)
.map(String.init)
.first
@@ -110,9 +110,9 @@ private extension PrepareURIPathUseCase {
return nil
}
guard let uriRest = matches.output.1 else {
return .forwardSlash
return .Path.forwardSlash
}
guard uriRest.hasPrefix(String.forwardSlash) else {
guard uriRest.hasPrefix(.Path.forwardSlash) else {
return .init(format: .Format.Path.root, uriRest)
}
return uriRest
@@ -50,7 +50,7 @@ struct RedirectURIUseCase {
statusCode: .movedPermanently,
redirect: uriPath
),
source: .source
source: .Logging.source
)
}
@@ -61,10 +61,3 @@ struct RedirectURIUseCase {
}
}
// MARK: - String+Constants
private extension String {
/// A name of the middleware that triggered a logging event.
static let source = "DocCMiddleware"
}
@@ -135,7 +135,7 @@ private extension Output {
/// A list of expected outputs for the URI path samples, regardless their match against suffixed or not suffixed root URI paths.
static let prepareURIPaths: [PrepareURIPathUseCase.PreparedURIPaths?] = [
("somearchive", "/SomeArchive.doccarchive", "/SomeArchive/some/content/path"),
(.empty, .empty, .forwardSlash),
(.empty, .empty, .Path.forwardSlash),
nil
]
}