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 { extension String {
/// An empty string. /// An empty string.
static let empty = "" static let empty = ""
/// A forwarding slash.
static let forwardSlash = "/" /// A namespace that defines logging representations.
/// An indication of a previous folder in a path component. enum Logging {
static let previousFolder = ".." /// 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? { func callAsFunction(_ uri: URI) -> String? {
guard guard
let uriPath = uri.path.removingPercentEncoding, let uriPath = uri.path.removingPercentEncoding,
!uriPath.contains(.previousFolder), !uriPath.contains(.Path.previousFolder),
uriPath.hasPrefix(.forwardSlash) uriPath.hasPrefix(.Path.forwardSlash)
else { else {
return nil return nil
} }
@@ -56,7 +56,7 @@ struct PrepareURIPathUseCase {
} }
let documentationName = uriRest let documentationName = uriRest
.split(separator: .forwardSlash) .split(separator: .Path.forwardSlash)
.map(String.init) .map(String.init)
.first .first
@@ -110,9 +110,9 @@ private extension PrepareURIPathUseCase {
return nil return nil
} }
guard let uriRest = matches.output.1 else { 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 .init(format: .Format.Path.root, uriRest)
} }
return uriRest return uriRest
@@ -50,7 +50,7 @@ struct RedirectURIUseCase {
statusCode: .movedPermanently, statusCode: .movedPermanently,
redirect: uriPath 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. /// 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?] = [ static let prepareURIPaths: [PrepareURIPathUseCase.PreparedURIPaths?] = [
("somearchive", "/SomeArchive.doccarchive", "/SomeArchive/some/content/path"), ("somearchive", "/SomeArchive.doccarchive", "/SomeArchive/some/content/path"),
(.empty, .empty, .forwardSlash), (.empty, .empty, .Path.forwardSlash),
nil nil
] ]
} }